blob: 7f0a9b82c36c80ecd16a3d93643fbc2a3e80e5fb [file] [log] [blame]
Craig Tiller535701c2015-12-07 10:09:44 -08001/*
2 *
3 * Copyright 2015, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34#include "test/core/bad_client/bad_client.h"
35#include "src/core/surface/server.h"
36
37#define PFX_STR \
38 "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \
39 "\x00\x00\x00\x04\x00\x00\x00\x00\x00"
40
41static void verifier(grpc_server *server, grpc_completion_queue *cq) {
42 while (grpc_server_has_open_connections(server)) {
43 GPR_ASSERT(grpc_completion_queue_next(
44 cq, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(20), NULL)
45 .type == GRPC_QUEUE_TIMEOUT);
46 }
47}
48
49int main(int argc, char **argv) {
50 grpc_test_init(argc, argv);
51
52 /* partial http2 header prefixes */
53 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00",
54 GRPC_BAD_CLIENT_DISCONNECT);
55 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00",
56 GRPC_BAD_CLIENT_DISCONNECT);
57 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x00",
58 GRPC_BAD_CLIENT_DISCONNECT);
59 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x00\x01",
60 GRPC_BAD_CLIENT_DISCONNECT);
61 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x00\x01\x00",
62 GRPC_BAD_CLIENT_DISCONNECT);
63 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x00\x01\x04",
64 GRPC_BAD_CLIENT_DISCONNECT);
65 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x00\x01\x05",
66 GRPC_BAD_CLIENT_DISCONNECT);
67 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x00\x01\x04\x00",
68 GRPC_BAD_CLIENT_DISCONNECT);
69 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x00\x01\x04\x00\x00",
70 GRPC_BAD_CLIENT_DISCONNECT);
71 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x00\x01\x04\x00\x00\x00",
72 GRPC_BAD_CLIENT_DISCONNECT);
73 GRPC_RUN_BAD_CLIENT_TEST(verifier,
74 PFX_STR "\x00\x00\x00\x01\x04\x00\x00\x00\x00",
75 GRPC_BAD_CLIENT_DISCONNECT);
76 GRPC_RUN_BAD_CLIENT_TEST(verifier,
77 PFX_STR "\x00\x00\x00\x01\x04\x00\x00\x00\x01",
78 GRPC_BAD_CLIENT_DISCONNECT);
79
80 /* test adding prioritization data */
81 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
82 "\x00\x00\x01\x01\x24\x00\x00\x00\x01"
83 "\x00",
84 0);
85 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
86 "\x00\x00\x02\x01\x24\x00\x00\x00\x01"
87 "\x00\x00",
88 0);
89 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
90 "\x00\x00\x03\x01\x24\x00\x00\x00\x01"
91 "\x00\x00\x00",
92 0);
93 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
94 "\x00\x00\x04\x01\x24\x00\x00\x00\x01"
95 "\x00\x00\x00\x00",
96 0);
97 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
98 "\x00\x00\x05\x01\x24\x00\x00\x00\x01"
Craig Tillere9307922015-12-08 08:37:36 -080099 "",
100 GRPC_BAD_CLIENT_DISCONNECT);
101 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
102 "\x00\x00\x05\x01\x24\x00\x00\x00\x01"
Craig Tiller85517c62015-12-07 21:15:17 -0800103 "\x00",
104 GRPC_BAD_CLIENT_DISCONNECT);
105 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
106 "\x00\x00\x05\x01\x24\x00\x00\x00\x01"
107 "\x00\x00",
108 GRPC_BAD_CLIENT_DISCONNECT);
109 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
110 "\x00\x00\x05\x01\x24\x00\x00\x00\x01"
111 "\x00\x00\x00",
112 GRPC_BAD_CLIENT_DISCONNECT);
113 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
114 "\x00\x00\x05\x01\x24\x00\x00\x00\x01"
115 "\x00\x00\x00\x00",
116 GRPC_BAD_CLIENT_DISCONNECT);
117 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
118 "\x00\x00\x05\x01\x24\x00\x00\x00\x01"
Craig Tiller535701c2015-12-07 10:09:44 -0800119 "\x00\x00\x00\x00\x00",
120 GRPC_BAD_CLIENT_DISCONNECT);
121
122 /* test looking up an invalid index */
123 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
124 "\x00\x00\x01\x01\x04\x00\x00\x00\x01"
125 "\xfe",
126 0);
127 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
128 "\x00\x00\x04\x01\x04\x00\x00\x00\x01"
Craig Tiller85517c62015-12-07 21:15:17 -0800129 "\x7f\x7f\x01""a",
Craig Tiller535701c2015-12-07 10:09:44 -0800130 0);
131 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
132 "\x00\x00\x04\x01\x04\x00\x00\x00\x01"
Craig Tiller85517c62015-12-07 21:15:17 -0800133 "\x0f\x7f\x01""a",
Craig Tiller535701c2015-12-07 10:09:44 -0800134 0);
135 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
136 "\x00\x00\x04\x01\x04\x00\x00\x00\x01"
Craig Tiller85517c62015-12-07 21:15:17 -0800137 "\x1f\x7f\x01""a",
Craig Tiller535701c2015-12-07 10:09:44 -0800138 0);
139 /* test nvr, not indexed in static table */
140 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
141 "\x00\x00\x03\x01\x04\x00\x00\x00\x01"
Craig Tiller85517c62015-12-07 21:15:17 -0800142 "\x01\x01""a",
Craig Tiller535701c2015-12-07 10:09:44 -0800143 GRPC_BAD_CLIENT_DISCONNECT);
144 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
145 "\x00\x00\x03\x01\x04\x00\x00\x00\x01"
Craig Tiller85517c62015-12-07 21:15:17 -0800146 "\x11\x01""a",
Craig Tiller535701c2015-12-07 10:09:44 -0800147 GRPC_BAD_CLIENT_DISCONNECT);
148 /* illegal op code */
149 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
150 "\x00\x00\x01\x01\x04\x00\x00\x00\x01"
151 "\x80",
152 0);
153 /* parse some long indices */
154 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
155 "\x00\x00\x02\x01\x04\x00\x00\x00\x01"
156 "\xff\x00",
157 0);
158 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
159 "\x00\x00\x03\x01\x04\x00\x00\x00\x01"
160 "\xff\x80\x00",
161 0);
162 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
163 "\x00\x00\x04\x01\x04\x00\x00\x00\x01"
164 "\xff\x80\x80\x00",
165 0);
166 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
167 "\x00\x00\x05\x01\x04\x00\x00\x00\x01"
168 "\xff\x80\x80\x80\x00",
169 0);
170 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
171 "\x00\x00\x06\x01\x04\x00\x00\x00\x01"
172 "\xff\x80\x80\x80\x80\x00",
173 0);
174 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
175 "\x00\x00\x07\x01\x04\x00\x00\x00\x01"
176 "\xff\x80\x80\x80\x80\x80\x00",
177 0);
178 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
179 "\x00\x00\x08\x01\x04\x00\x00\x00\x01"
Craig Tillere9307922015-12-08 08:37:36 -0800180 "\xff",
181 GRPC_BAD_CLIENT_DISCONNECT);
182 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
183 "\x00\x00\x08\x01\x04\x00\x00\x00\x01"
184 "\xff\x80",
185 GRPC_BAD_CLIENT_DISCONNECT);
186 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
187 "\x00\x00\x08\x01\x04\x00\x00\x00\x01"
188 "\xff\x80\x80",
189 GRPC_BAD_CLIENT_DISCONNECT);
190 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
191 "\x00\x00\x08\x01\x04\x00\x00\x00\x01"
192 "\xff\x80\x80\x80",
193 GRPC_BAD_CLIENT_DISCONNECT);
194 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
195 "\x00\x00\x08\x01\x04\x00\x00\x00\x01"
196 "\xff\x80\x80\x80\x80",
197 GRPC_BAD_CLIENT_DISCONNECT);
198 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
199 "\x00\x00\x08\x01\x04\x00\x00\x00\x01"
200 "\xff\x80\x80\x80\x80\x80",
201 GRPC_BAD_CLIENT_DISCONNECT);
202 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
203 "\x00\x00\x08\x01\x04\x00\x00\x00\x01"
204 "\xff\x80\x80\x80\x80\x80\x80",
205 GRPC_BAD_CLIENT_DISCONNECT);
206 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
207 "\x00\x00\x08\x01\x04\x00\x00\x00\x01"
Craig Tiller535701c2015-12-07 10:09:44 -0800208 "\xff\x80\x80\x80\x80\x80\x80\x00",
209 0);
Craig Tillerd391b562015-12-08 08:53:09 -0800210 /* overflow on byte 4 */
211 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
212 "\x00\x00\x06\x01\x04\x00\x00\x00\x01"
213 "\xff\x80\x80\x80\x80\x7f",
214 GRPC_BAD_CLIENT_DISCONNECT);
215 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
216 "\x00\x00\x06\x01\x04\x00\x00\x00\x01"
217 "\xff\xff\xff\xff\xff\x0f",
218 GRPC_BAD_CLIENT_DISCONNECT);
219 /* overflow after byte 4 */
220 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
221 "\x00\x00\x08\x01\x04\x00\x00\x00\x01"
222 "\xff\x80\x80\x80\x80\x80\x80\x02",
223 0);
Craig Tiller535701c2015-12-07 10:09:44 -0800224 /* end of headers mid-opcode */
225 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
226 "\x00\x00\x01\x01\x04\x00\x00\x00\x01"
227 "\x01",
228 GRPC_BAD_CLIENT_DISCONNECT);
229
Craig Tillere219e022015-12-07 10:58:55 -0800230 /* dynamic table size update: set to default */
231 GRPC_RUN_BAD_CLIENT_TEST(verifier,
232 PFX_STR
233 "\x00\x00\x03\x01\x04\x00\x00\x00\x01"
234 "\x3f\xe1\x1f",
235 GRPC_BAD_CLIENT_DISCONNECT);
Craig Tillerd391b562015-12-08 08:53:09 -0800236 /* dynamic table size update: set too large */
Craig Tillere219e022015-12-07 10:58:55 -0800237 GRPC_RUN_BAD_CLIENT_TEST(verifier,
238 PFX_STR
239 "\x00\x00\x03\x01\x04\x00\x00\x00\x01"
240 "\x3f\xf1\x1f",
241 0);
Craig Tillerd391b562015-12-08 08:53:09 -0800242 /* dynamic table size update: set twice */
243 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
244 "\x00\x00\x04\x01\x04\x00\x00\x00\x01"
245 "\x20\x3f\xe1\x1f",
246 GRPC_BAD_CLIENT_DISCONNECT);
247 /* dynamic table size update: set thrice */
248 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
249 "\x00\x00\x03\x01\x04\x00\x00\x00\x01"
250 "\x20\x20\x20",
251 0);
Craig Tillere219e022015-12-07 10:58:55 -0800252
253 /* non-ending header followed by continuation frame */
254 GRPC_RUN_BAD_CLIENT_TEST(verifier,
255 PFX_STR
256 "\x00\x00\x00\x01\x00\x00\x00\x00\x01"
257 "\x00\x00\x00\x09\x04\x00\x00\x00\x01",
258 GRPC_BAD_CLIENT_DISCONNECT);
259 /* non-ending header followed by non-continuation frame */
260 GRPC_RUN_BAD_CLIENT_TEST(verifier,
261 PFX_STR
262 "\x00\x00\x00\x01\x00\x00\x00\x00\x01"
263 "\x00\x00\x00\x00\x04\x00\x00\x00\x01",
264 0);
Craig Tiller09c2d6d2015-12-07 11:52:12 -0800265 /* opening with a continuation frame */
266 GRPC_RUN_BAD_CLIENT_TEST(verifier,
267 PFX_STR
268 "\x00\x00\x00\x09\x04\x00\x00\x00\x01",
269 0);
Craig Tillere219e022015-12-07 10:58:55 -0800270
Craig Tillerc3218142015-12-08 08:30:39 -0800271 /* an invalid header found with fuzzing */
272 GRPC_RUN_BAD_CLIENT_TEST(verifier,
273 PFX_STR
274 "\x00\x00\x00\x01\x39\x67\xed\x1d\x64",
275 GRPC_BAD_CLIENT_DISCONNECT);
276
Craig Tiller25fd5712015-12-09 08:58:47 -0800277 /* a badly encoded timeout value */
278 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
279 "\x00\x00\x19\x01\x04\x00\x00\x00\x01"
280 "\x10\x0cgrpc-timeout\x0a"
281 "15 seconds",
282 GRPC_BAD_CLIENT_DISCONNECT);
283 /* a badly encoded timeout value: twice (catches caching) */
284 GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
285 "\x00\x00\x19\x01\x04\x00\x00\x00\x01"
286 "\x10\x0cgrpc-timeout\x0a"
287 "15 seconds"
288 "\x00\x00\x19\x01\x04\x00\x00\x00\x03"
289 "\x10\x0cgrpc-timeout\x0a"
290 "15 seconds",
291 GRPC_BAD_CLIENT_DISCONNECT);
292
Craig Tiller535701c2015-12-07 10:09:44 -0800293 return 0;
294}