headers.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 
21 
22 #define PFX_STR \
23  "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \
24  "\x00\x00\x00\x04\x00\x00\x00\x00\x00"
25 
27  void* /*registered_method*/) {
28  while (grpc_core::Server::FromC(server)->HasOpenConnections()) {
32  }
33 }
34 
35 int main(int argc, char** argv) {
37  grpc_init();
38 
39  /* partial http2 header prefixes */
40  GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00",
42  GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x00",
44  GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x00\x00",
46  GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x00\x00\x01",
48  GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x00\x00\x01\x00",
50  GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x00\x00\x01\x04",
52  GRPC_RUN_BAD_CLIENT_TEST(verifier, nullptr, PFX_STR "\x00\x00\x00\x01\x05",
55  PFX_STR "\x00\x00\x00\x01\x04\x00",
58  PFX_STR "\x00\x00\x00\x01\x04\x00\x00",
61  PFX_STR "\x00\x00\x00\x01\x04\x00\x00\x00",
64  PFX_STR "\x00\x00\x00\x01\x04\x00\x00\x00\x00",
67  PFX_STR "\x00\x00\x00\x01\x04\x00\x00\x00\x01",
69 
70  /* test adding prioritization data */
72  PFX_STR
73  "\x00\x00\x01\x01\x24\x00\x00\x00\x01"
74  "\x00",
75  0);
77  PFX_STR
78  "\x00\x00\x02\x01\x24\x00\x00\x00\x01"
79  "\x00\x00",
80  0);
82  PFX_STR
83  "\x00\x00\x03\x01\x24\x00\x00\x00\x01"
84  "\x00\x00\x00",
85  0);
87  PFX_STR
88  "\x00\x00\x04\x01\x24\x00\x00\x00\x01"
89  "\x00\x00\x00\x00",
90  0);
92  PFX_STR
93  "\x00\x00\x05\x01\x24\x00\x00\x00\x01"
94  "",
97  PFX_STR
98  "\x00\x00\x05\x01\x24\x00\x00\x00\x01"
99  "\x00",
102  PFX_STR
103  "\x00\x00\x05\x01\x24\x00\x00\x00\x01"
104  "\x00\x00",
107  PFX_STR
108  "\x00\x00\x05\x01\x24\x00\x00\x00\x01"
109  "\x00\x00\x00",
112  PFX_STR
113  "\x00\x00\x05\x01\x24\x00\x00\x00\x01"
114  "\x00\x00\x00\x00",
117  PFX_STR
118  "\x00\x00\x05\x01\x24\x00\x00\x00\x01"
119  "\x00\x00\x00\x00\x00",
121 
122  /* test looking up an invalid index */
124  PFX_STR
125  "\x00\x00\x01\x01\x04\x00\x00\x00\x01"
126  "\xfe",
127  0);
129  PFX_STR
130  "\x00\x00\x04\x01\x04\x00\x00\x00\x01"
131  "\x7f\x7f\x01"
132  "a",
133  0);
135  PFX_STR
136  "\x00\x00\x04\x01\x04\x00\x00\x00\x01"
137  "\x0f\x7f\x01"
138  "a",
139  0);
141  PFX_STR
142  "\x00\x00\x04\x01\x04\x00\x00\x00\x01"
143  "\x1f\x7f\x01"
144  "a",
145  0);
146  /* test nvr, not indexed in static table */
148  PFX_STR
149  "\x00\x00\x03\x01\x04\x00\x00\x00\x01"
150  "\x01\x01"
151  "a",
154  PFX_STR
155  "\x00\x00\x03\x01\x04\x00\x00\x00\x01"
156  "\x11\x01"
157  "a",
159  /* illegal op code */
161  PFX_STR
162  "\x00\x00\x01\x01\x04\x00\x00\x00\x01"
163  "\x80",
164  0);
165  /* parse some long indices */
167  PFX_STR
168  "\x00\x00\x02\x01\x04\x00\x00\x00\x01"
169  "\xff\x00",
170  0);
172  PFX_STR
173  "\x00\x00\x03\x01\x04\x00\x00\x00\x01"
174  "\xff\x80\x00",
175  0);
177  PFX_STR
178  "\x00\x00\x04\x01\x04\x00\x00\x00\x01"
179  "\xff\x80\x80\x00",
180  0);
182  PFX_STR
183  "\x00\x00\x05\x01\x04\x00\x00\x00\x01"
184  "\xff\x80\x80\x80\x00",
185  0);
187  PFX_STR
188  "\x00\x00\x06\x01\x04\x00\x00\x00\x01"
189  "\xff\x80\x80\x80\x80\x00",
190  0);
192  PFX_STR
193  "\x00\x00\x07\x01\x04\x00\x00\x00\x01"
194  "\xff\x80\x80\x80\x80\x80\x00",
195  0);
197  PFX_STR
198  "\x00\x00\x08\x01\x04\x00\x00\x00\x01"
199  "\xff",
202  PFX_STR
203  "\x00\x00\x08\x01\x04\x00\x00\x00\x01"
204  "\xff\x80",
207  PFX_STR
208  "\x00\x00\x08\x01\x04\x00\x00\x00\x01"
209  "\xff\x80\x80",
212  PFX_STR
213  "\x00\x00\x08\x01\x04\x00\x00\x00\x01"
214  "\xff\x80\x80\x80",
217  PFX_STR
218  "\x00\x00\x08\x01\x04\x00\x00\x00\x01"
219  "\xff\x80\x80\x80\x80",
222  PFX_STR
223  "\x00\x00\x08\x01\x04\x00\x00\x00\x01"
224  "\xff\x80\x80\x80\x80\x80",
227  PFX_STR
228  "\x00\x00\x08\x01\x04\x00\x00\x00\x01"
229  "\xff\x80\x80\x80\x80\x80\x80",
232  PFX_STR
233  "\x00\x00\x08\x01\x04\x00\x00\x00\x01"
234  "\xff\x80\x80\x80\x80\x80\x80\x00",
235  0);
236  /* overflow on byte 4 */
238  PFX_STR
239  "\x00\x00\x06\x01\x04\x00\x00\x00\x01"
240  "\xff\x80\x80\x80\x80\x7f",
243  PFX_STR
244  "\x00\x00\x06\x01\x04\x00\x00\x00\x01"
245  "\xff\xff\xff\xff\xff\x0f",
247  /* overflow after byte 4 */
249  PFX_STR
250  "\x00\x00\x08\x01\x04\x00\x00\x00\x01"
251  "\xff\x80\x80\x80\x80\x80\x80\x02",
252  0);
253  /* end of headers mid-opcode */
255  PFX_STR
256  "\x00\x00\x01\x01\x04\x00\x00\x00\x01"
257  "\x01",
259 
260  /* dynamic table size update: set to default */
262  PFX_STR
263  "\x00\x00\x03\x01\x04\x00\x00\x00\x01"
264  "\x3f\xe1\x1f",
266  /* dynamic table size update: set too large */
268  PFX_STR
269  "\x00\x00\x03\x01\x04\x00\x00\x00\x01"
270  "\x3f\xf1\x1f",
271  0);
272  /* dynamic table size update: set twice */
274  PFX_STR
275  "\x00\x00\x04\x01\x04\x00\x00\x00\x01"
276  "\x20\x3f\xe1\x1f",
278  /* dynamic table size update: set thrice */
280  PFX_STR
281  "\x00\x00\x03\x01\x04\x00\x00\x00\x01"
282  "\x20\x20\x20",
283  0);
284 
285  /* non-ending header followed by continuation frame */
287  PFX_STR
288  "\x00\x00\x00\x01\x00\x00\x00\x00\x01"
289  "\x00\x00\x00\x09\x04\x00\x00\x00\x01",
291  /* non-ending header followed by non-continuation frame */
293  PFX_STR
294  "\x00\x00\x00\x01\x00\x00\x00\x00\x01"
295  "\x00\x00\x00\x00\x04\x00\x00\x00\x01",
296  0);
297  /* non-ending header followed by a continuation frame for a different stream
298  */
300  PFX_STR
301  "\x00\x00\x00\x01\x04\x00\x00\x00\x01"
302  "\x00\x00\x00\x01\x00\x00\x00\x00\x03"
303  "\x00\x00\x00\x09\x04\x00\x00\x00\x01",
304  0);
305  /* opening with a continuation frame */
307  PFX_STR "\x00\x00\x00\x09\x04\x00\x00\x00\x01", 0);
308  /* three header frames */
310  PFX_STR
311  "\x00\x00\x00\x01\x04\x00\x00\x00\x01"
312  "\x00\x00\x00\x01\x04\x00\x00\x00\x01"
313  "\x00\x00\x00\x01\x04\x00\x00\x00\x01",
315 
316  /* an invalid header found with fuzzing */
318  PFX_STR "\x00\x00\x00\x01\x39\x67\xed\x1d\x64",
320 
321  /* a badly encoded timeout value */
323  PFX_STR
324  "\x00\x00\x19\x01\x04\x00\x00\x00\x01"
325  "\x10\x0cgrpc-timeout\x0a"
326  "15 seconds",
328  /* a badly encoded timeout value: twice (catches caching) */
330  PFX_STR
331  "\x00\x00\x19\x01\x04\x00\x00\x00\x01"
332  "\x10\x0cgrpc-timeout\x0a"
333  "15 seconds"
334  "\x00\x00\x19\x01\x04\x00\x00\x00\x03"
335  "\x10\x0cgrpc-timeout\x0a"
336  "15 seconds",
338 
339  grpc_shutdown();
340  return 0;
341 }
generate.env
env
Definition: generate.py:37
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
verifier
static void verifier(grpc_server *server, grpc_completion_queue *cq, void *)
Definition: headers.cc:26
grpc_server
struct grpc_server grpc_server
Definition: grpc_types.h:65
GRPC_BAD_CLIENT_DISCONNECT
#define GRPC_BAD_CLIENT_DISCONNECT
Definition: bad_client.h:48
server
Definition: examples/python/async_streaming/server.py:1
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
main
int main(int argc, char **argv)
Definition: headers.cc:35
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
PFX_STR
#define PFX_STR
Definition: headers.cc:22
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 03:00:12