badreq.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 
26 
27 #define PFX_STR \
28  "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \
29  "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */
30 
32  void* /*registered_method*/) {
33  while (grpc_core::Server::FromC(server)->HasOpenConnections()) {
37  }
38 }
39 
40 int main(int argc, char** argv) {
42  grpc_init();
43 
44  /* invalid content type */
46  verifier, nullptr,
47  PFX_STR
48  "\x00\x00\xc2\x01\x04\x00\x00\x00\x01"
49  "\x10\x05:path\x08/foo/bar"
50  "\x10\x07:scheme\x04http"
51  "\x10\x07:method\x04POST"
52  "\x10\x0a:authority\x09localhost"
53  "\x10\x0c"
54  "content-type\x09text/html"
55  "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip"
56  "\x10\x02te\x08trailers"
57  "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
59 
60  /* invalid te */
62  verifier, nullptr,
63  PFX_STR
64  "\x00\x00\xcb\x01\x04\x00\x00\x00\x01"
65  "\x10\x05:path\x08/foo/bar"
66  "\x10\x07:scheme\x04http"
67  "\x10\x07:method\x04POST"
68  "\x10\x0a:authority\x09localhost"
69  "\x10\x0c"
70  "content-type\x10"
71  "application/grpc"
72  "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip"
73  "\x10\x02te\x0a"
74  "frobnicate"
75  "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
77 
78  /* two path headers */
80  verifier, nullptr,
81  PFX_STR
82  "\x00\x00\xd9\x01\x04\x00\x00\x00\x01"
83  "\x10\x05:path\x08/foo/bar"
84  "\x10\x05:path\x08/foo/bah"
85  "\x10\x07:scheme\x04http"
86  "\x10\x07:method\x04POST"
87  "\x10\x0a:authority\x09localhost"
88  "\x10\x0c"
89  "content-type\x10"
90  "application/grpc"
91  "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip"
92  "\x10\x02te\x08trailers"
93  "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
95 
96  /* bad accept-encoding algorithm */
98  verifier, nullptr,
99  PFX_STR
100  "\x00\x00\xd2\x01\x04\x00\x00\x00\x01"
101  "\x10\x05:path\x08/foo/bar"
102  "\x10\x07:scheme\x04http"
103  "\x10\x07:method\x04POST"
104  "\x10\x0a:authority\x09localhost"
105  "\x10\x0c"
106  "content-type\x10"
107  "application/grpc"
108  "\x10\x14grpc-accept-encoding\x1enobody-knows-the-trouble-i-see"
109  "\x10\x02te\x08trailers"
110  "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
112 
113  /* bad grpc-encoding algorithm */
115  verifier, nullptr,
116  PFX_STR
117  "\x00\x00\xf5\x01\x04\x00\x00\x00\x01"
118  "\x10\x05:path\x08/foo/bar"
119  "\x10\x07:scheme\x04http"
120  "\x10\x07:method\x04POST"
121  "\x10\x0a:authority\x09localhost"
122  "\x10\x0c"
123  "content-type\x10"
124  "application/grpc"
125  "\x10\x14grpc-accept-encoding\x15identity,deflate,gzip"
126  "\x10\x0dgrpc-encoding\x1cyou-dont-know-how-to-do-this"
127  "\x10\x02te\x08trailers"
128  "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
130 
131  grpc_shutdown();
132  return 0;
133 }
generate.env
env
Definition: generate.py:37
string.h
verifier
static void verifier(grpc_server *server, grpc_completion_queue *cq, void *)
Definition: badreq.cc:31
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
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
main
int main(int argc, char **argv)
Definition: badreq.cc:40
GRPC_BAD_CLIENT_DISCONNECT
#define GRPC_BAD_CLIENT_DISCONNECT
Definition: bad_client.h:48
cq_verifier.h
server
Definition: examples/python/async_streaming/server.py:1
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
PFX_STR
#define PFX_STR
Definition: badreq.cc:27
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
GRPC_RUN_BAD_CLIENT_TEST
#define GRPC_RUN_BAD_CLIENT_TEST(server_validator, client_validator, payload, flags)
Definition: bad_client.h:71
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
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
GRPC_QUEUE_TIMEOUT
@ GRPC_QUEUE_TIMEOUT
Definition: grpc_types.h:556
grpc_shutdown
GRPCAPI void grpc_shutdown(void)
Definition: init.cc:209
bad_client.h
cq
static grpc_completion_queue * cq
Definition: test/core/fling/client.cc:37


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:35