window_overflow.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #include <string.h>
20 
21 #include <grpc/grpc.h>
22 #include <grpc/support/alloc.h>
23 
26 
27 #define PFX_STR \
28  "\x00\x00\x00\x04\x01\x00\x00\x00\x00" \
29  "\x00\x00\xc9\x01\x04\x00\x00\x00\x01" /* headers: generated from \
30  simple_request.headers in this \
31  directory */ \
32  "\x10\x05:path\x08/foo/bar" \
33  "\x10\x07:scheme\x04http" \
34  "\x10\x07:method\x04POST" \
35  "\x10\x0a:authority\x09localhost" \
36  "\x10\x0c" \
37  "content-type\x10" \
38  "application/grpc" \
39  "\x10\x14grpc-accept-encoding\x15" \
40  "deflate,identity,gzip" \
41  "\x10\x02te\x08trailers" \
42  "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)"
43 
45  void* /*registered_method*/) {
46  while (grpc_core::Server::FromC(server)->HasOpenConnections()) {
50  }
51 }
52 
53 char* g_buffer;
54 size_t g_cap = 0;
55 size_t g_count = 0;
56 
57 static void addbuf(const void* data, size_t len) {
58  if (g_count + len > g_cap) {
59  g_cap = std::max(g_count + len, g_cap * 2);
60  g_buffer = static_cast<char*>(gpr_realloc(g_buffer, g_cap));
61  }
63  g_count += len;
64 }
65 
66 int main(int argc, char** argv) {
67  int i, j;
68 #define MAX_FRAME_SIZE 16384
69 #define MESSAGES_PER_FRAME (MAX_FRAME_SIZE / 5)
70 #define FRAME_SIZE (MESSAGES_PER_FRAME * 5)
71 #define SEND_SIZE (4 * 1024 * 1024)
72 #define NUM_FRAMES (SEND_SIZE / FRAME_SIZE + 1)
74  grpc_init();
75 
76  addbuf(PFX_STR, sizeof(PFX_STR) - 1);
77  for (i = 0; i < NUM_FRAMES; i++) {
78  uint8_t hdr[9] = {static_cast<uint8_t>(FRAME_SIZE >> 16),
79  static_cast<uint8_t>(FRAME_SIZE >> 8),
80  static_cast<uint8_t>
81  FRAME_SIZE,
82  0,
83  0,
84  0,
85  0,
86  0,
87  1};
88  addbuf(hdr, sizeof(hdr));
89  for (j = 0; j < MESSAGES_PER_FRAME; j++) {
90  uint8_t message[5] = {0, 0, 0, 0, 0};
91  addbuf(message, sizeof(message));
92  }
93  }
94  grpc_bad_client_arg bca[2];
95  bca[0] = connection_preface_arg;
96  bca[1] = {rst_stream_client_validator, nullptr, g_buffer, g_count};
99  grpc_shutdown();
100 
101  return 0;
102 }
absl::str_format_internal::LengthMod::j
@ j
generate.env
env
Definition: generate.py:37
string.h
gpr_free
GPRAPI void gpr_free(void *ptr)
Definition: alloc.cc:51
addbuf
static void addbuf(const void *data, size_t len)
Definition: window_overflow.cc:55
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
main
int main(int argc, char **argv)
Definition: window_overflow.cc:64
message
char * message
Definition: libuv/docs/code/tty-gravity/main.c:12
NUM_FRAMES
#define NUM_FRAMES
FRAME_SIZE
#define FRAME_SIZE
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
gpr_realloc
GPRAPI void * gpr_realloc(void *p, size_t size)
Definition: alloc.cc:56
max
int max
Definition: bloaty/third_party/zlib/examples/enough.c:170
grpc_timeout_milliseconds_to_deadline
gpr_timespec grpc_timeout_milliseconds_to_deadline(int64_t time_ms)
Definition: test/core/util/test_config.cc:89
grpc_completion_queue
Definition: completion_queue.cc:347
grpc.h
grpc_server
struct grpc_server grpc_server
Definition: grpc_types.h:65
g_buffer
char * g_buffer
Definition: window_overflow.cc:51
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
GRPC_BAD_CLIENT_LARGE_REQUEST
#define GRPC_BAD_CLIENT_LARGE_REQUEST
Definition: bad_client.h:49
PFX_STR
#define PFX_STR
Definition: window_overflow.cc:27
server
Definition: examples/python/async_streaming/server.py:1
grpc_run_bad_client_test
void grpc_run_bad_client_test(grpc_bad_client_server_side_validator server_validator, grpc_bad_client_arg args[], int num_args, uint32_t flags)
Definition: bad_client.cc:193
grpc_bad_client_arg
Definition: bad_client.h:40
alloc.h
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
grpc_completion_queue_next
GRPCAPI grpc_event grpc_completion_queue_next(grpc_completion_queue *cq, gpr_timespec deadline, void *reserved)
Definition: completion_queue.cc:1133
server.h
rst_stream_client_validator
bool rst_stream_client_validator(grpc_slice_buffer *incoming, void *)
Definition: bad_client.cc:286
connection_preface_arg
grpc_bad_client_arg connection_preface_arg
Definition: bad_client.cc:282
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
grpc_init
GRPCAPI void grpc_init(void)
Definition: init.cc:146
grpc_core::CppImplOf< Server, grpc_server >::FromC
static Server * FromC(grpc_server *c_type)
Definition: cpp_impl_of.h:30
verifier
static void verifier(grpc_server *server, grpc_completion_queue *cq, void *)
Definition: window_overflow.cc:42
GRPC_QUEUE_TIMEOUT
@ GRPC_QUEUE_TIMEOUT
Definition: grpc_types.h:556
grpc_shutdown
GRPCAPI void grpc_shutdown(void)
Definition: init.cc:209
MESSAGES_PER_FRAME
#define MESSAGES_PER_FRAME
bad_client.h
g_count
size_t g_count
Definition: window_overflow.cc:53
cq
static grpc_completion_queue * cq
Definition: test/core/fling/client.cc:37
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
g_cap
size_t g_cap
Definition: window_overflow.cc:52


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:51