Skip to content

Commit 573457b

Browse files
committed
Merge pull request grpc#6203 from ctiller/dictionary
Add a dictionary for fuzzing
2 parents faaeab0 + 134a6b6 commit 573457b

File tree

95 files changed

+2530
-605
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+2530
-605
lines changed

build.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,7 @@ targets:
11871187
- gpr
11881188
corpus_dirs:
11891189
- test/core/end2end/fuzzers/client_fuzzer_corpus
1190+
dict: test/core/end2end/fuzzers/hpack.dictionary
11901191
maxlen: 2048
11911192
- name: compression_test
11921193
build: test
@@ -1676,6 +1677,7 @@ targets:
16761677
- gpr
16771678
corpus_dirs:
16781679
- test/core/transport/chttp2/hpack_parser_corpus
1680+
dict: test/core/end2end/fuzzers/hpack.dictionary
16791681
maxlen: 512
16801682
- name: hpack_parser_test
16811683
build: test
@@ -2027,6 +2029,7 @@ targets:
20272029
- gpr
20282030
corpus_dirs:
20292031
- test/core/end2end/fuzzers/server_fuzzer_corpus
2032+
dict: test/core/end2end/fuzzers/hpack.dictionary
20302033
maxlen: 2048
20312034
- name: server_test
20322035
build: test

src/core/ext/transport/chttp2/transport/hpack_parser.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,10 @@ static int on_hdr(grpc_chttp2_hpack_parser *p, grpc_mdelem *md,
638638
return 0;
639639
}
640640
}
641+
if (p->on_header == NULL) {
642+
grpc_mdelem_unref(md);
643+
return 0;
644+
}
641645
p->on_header(p->on_header_user_data, md);
642646
return 1;
643647
}
@@ -1382,12 +1386,8 @@ static int parse_value_string_with_literal_key(grpc_chttp2_hpack_parser *p,
13821386

13831387
/* PUBLIC INTERFACE */
13841388

1385-
static void on_header_not_set(void *user_data, grpc_mdelem *md) {
1386-
GPR_UNREACHABLE_CODE(return );
1387-
}
1388-
13891389
void grpc_chttp2_hpack_parser_init(grpc_chttp2_hpack_parser *p) {
1390-
p->on_header = on_header_not_set;
1390+
p->on_header = NULL;
13911391
p->on_header_user_data = NULL;
13921392
p->state = parse_begin;
13931393
p->key.str = NULL;
@@ -1455,7 +1455,7 @@ grpc_chttp2_parse_error grpc_chttp2_header_parser_parse(
14551455
stream_parsing->received_close = 1;
14561456
}
14571457
}
1458-
parser->on_header = on_header_not_set;
1458+
parser->on_header = NULL;
14591459
parser->on_header_user_data = NULL;
14601460
parser->is_boundary = 0xde;
14611461
parser->is_eof = 0xde;

templates/tools/fuzzer/runners.template

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ template: |
3737

3838
flags="-max_total_time=$runtime -artifact_prefix=fuzzer_output/ -max_len=${selected.maxlen}"
3939

40+
%if selected.get('dict'):
41+
flags="$flags -dict=${selected.dict}"
42+
%endif
43+
4044
if [ "$jobs" != "1" ]
4145
then
4246
flags="-jobs=$jobs -workers=$jobs $flags"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!m��!��������
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!m�!���������
+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# hpack fuzzing dictionary
2+
kw0="\x01""0"
3+
kw1="\x01""1"
4+
kw2="\x01""2"
5+
kw3="\x03""200"
6+
kw4="\x03""204"
7+
kw5="\x03""206"
8+
kw6="\x03""304"
9+
kw7="\x03""400"
10+
kw8="\x03""404"
11+
kw9="\x03""500"
12+
kw10="\x06""accept"
13+
kw11="\x0e""accept-charset"
14+
kw12="\x0f""accept-encoding"
15+
kw13="\x0f""accept-language"
16+
kw14="\x0d""accept-ranges"
17+
kw15="\x1b""access-control-allow-origin"
18+
kw16="\x03""age"
19+
kw17="\x05""allow"
20+
kw18="\x10""application/grpc"
21+
kw19="\x0a:authority"
22+
kw20="\x0d""authorization"
23+
kw21="\x0d""cache-control"
24+
kw22="\x0a""census-bin"
25+
kw23="\x11""census-binary-bin"
26+
kw24="\x13""content-disposition"
27+
kw25="\x10""content-encoding"
28+
kw26="\x10""content-language"
29+
kw27="\x0e""content-length"
30+
kw28="\x10""content-location"
31+
kw29="\x0d""content-range"
32+
kw30="\x0c""content-type"
33+
kw31="\x06""cookie"
34+
kw32="\x04""date"
35+
kw33="\x07""deflate"
36+
kw34="\x0c""deflate,gzip"
37+
kw35="\x00"
38+
kw36="\x04""etag"
39+
kw37="\x06""expect"
40+
kw38="\x07""expires"
41+
kw39="\x04""from"
42+
kw40="\x03GET"
43+
kw41="\x04grpc"
44+
kw42="\x14grpc-accept-encoding"
45+
kw43="\x0dgrpc-encoding"
46+
kw44="\x1egrpc-internal-encoding-request"
47+
kw45="\x0cgrpc-message"
48+
kw46="\x0bgrpc-status"
49+
kw47="\x0cgrpc-timeout"
50+
kw48="\x04gzip"
51+
kw49="\x0dgzip, deflate"
52+
kw50="\x04host"
53+
kw51="\x04http"
54+
kw52="\x05https"
55+
kw53="\x08identity"
56+
kw54="\x10identity,deflate"
57+
kw55="\x15identity,deflate,gzip"
58+
kw56="\x0didentity,gzip"
59+
kw57="\x08if-match"
60+
kw58="\x11if-modified-since"
61+
kw59="\x0dif-none-match"
62+
kw60="\x08if-range"
63+
kw61="\x13if-unmodified-since"
64+
kw62="\x0dlast-modified"
65+
kw63="\x04link"
66+
kw64="\x08location"
67+
kw65="\x0cmax-forwards"
68+
kw66="\x07:method"
69+
kw67="\x05:path"
70+
kw68="\x04POST"
71+
kw69="\x12proxy-authenticate"
72+
kw70="\x13proxy-authorization"
73+
kw71="\x03PUT"
74+
kw72="\x05range"
75+
kw73="\x07referer"
76+
kw74="\x07refresh"
77+
kw75="\x0bretry-after"
78+
kw76="\x07:scheme"
79+
kw77="\x06server"
80+
kw78="\x0aset-cookie"
81+
kw79="\x01/"
82+
kw80="\x0b/index.html"
83+
kw81="\x07:status"
84+
kw82="\x19strict-transport-security"
85+
kw83="\x02te"
86+
kw84="\x08trailers"
87+
kw85="\x11transfer-encoding"
88+
kw86="\x0auser-agent"
89+
kw87="\x04vary"
90+
kw88="\x03via"
91+
kw89="\x10www-authenticate"

tools/codegen/core/gen_static_metadata.py

+32
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ def put_banner(files, banner):
205205
args = sys.argv[1:]
206206
H = None
207207
C = None
208+
D = None
208209
if args:
209210
if 'header' in args:
210211
H = sys.stdout
@@ -214,11 +215,17 @@ def put_banner(files, banner):
214215
C = sys.stdout
215216
else:
216217
C = open('/dev/null', 'w')
218+
if 'dictionary' in args:
219+
D = sys.stdout
220+
else:
221+
D = open('/dev/null', 'w')
217222
else:
218223
H = open(os.path.join(
219224
os.path.dirname(sys.argv[0]), '../../../src/core/lib/transport/static_metadata.h'), 'w')
220225
C = open(os.path.join(
221226
os.path.dirname(sys.argv[0]), '../../../src/core/lib/transport/static_metadata.c'), 'w')
227+
D = open(os.path.join(
228+
os.path.dirname(sys.argv[0]), '../../../test/core/end2end/fuzzers/hpack.dictionary'), 'w')
222229

223230
# copy-paste copyright notice from this file
224231
with open(sys.argv[0]) as my_source:
@@ -235,6 +242,27 @@ def put_banner(files, banner):
235242
copyright.append(line)
236243
put_banner([H,C], [line[2:].rstrip() for line in copyright])
237244

245+
246+
hex_bytes = [ord(c) for c in "abcdefABCDEF0123456789"]
247+
248+
249+
def esc_c(line):
250+
out = "\""
251+
last_was_hex = False
252+
for c in line:
253+
if 32 <= c < 127:
254+
if c in hex_bytes and last_was_hex:
255+
out += "\"\""
256+
if c != ord('"'):
257+
out += chr(c)
258+
else:
259+
out += "\\\""
260+
last_was_hex = False
261+
else:
262+
out += "\\x%02x" % c
263+
last_was_hex = True
264+
return out + "\""
265+
238266
put_banner([H,C],
239267
"""WARNING: Auto-generated code.
240268
@@ -263,6 +291,10 @@ def put_banner(files, banner):
263291
print >>C, 'grpc_mdstr grpc_static_mdstr_table[GRPC_STATIC_MDSTR_COUNT];'
264292
print >>C
265293

294+
print >>D, '# hpack fuzzing dictionary'
295+
for i, elem in enumerate(all_strs):
296+
print >>D, 'kw%d=%s' % (i, esc_c([len(elem)] + [ord(c) for c in elem]))
297+
266298
print >>H, '#define GRPC_STATIC_MDELEM_COUNT %d' % len(all_elems)
267299
print >>H, 'extern grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT];'
268300
print >>H, 'extern uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT];'

tools/fuzzer/runners/client_fuzzer.sh

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
flags="-max_total_time=$runtime -artifact_prefix=fuzzer_output/ -max_len=2048"
3333

34+
flags="$flags -dict=test/core/end2end/fuzzers/hpack.dictionary"
35+
3436
if [ "$jobs" != "1" ]
3537
then
3638
flags="-jobs=$jobs -workers=$jobs $flags"

tools/fuzzer/runners/hpack_parser_fuzzer_test.sh

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
flags="-max_total_time=$runtime -artifact_prefix=fuzzer_output/ -max_len=512"
3333

34+
flags="$flags -dict=test/core/end2end/fuzzers/hpack.dictionary"
35+
3436
if [ "$jobs" != "1" ]
3537
then
3638
flags="-jobs=$jobs -workers=$jobs $flags"

tools/fuzzer/runners/http_fuzzer_test.sh

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
flags="-max_total_time=$runtime -artifact_prefix=fuzzer_output/ -max_len=2048"
3333

34+
3435
if [ "$jobs" != "1" ]
3536
then
3637
flags="-jobs=$jobs -workers=$jobs $flags"

tools/fuzzer/runners/json_fuzzer_test.sh

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
flags="-max_total_time=$runtime -artifact_prefix=fuzzer_output/ -max_len=512"
3333

34+
3435
if [ "$jobs" != "1" ]
3536
then
3637
flags="-jobs=$jobs -workers=$jobs $flags"

tools/fuzzer/runners/nanopb_fuzzer_response_test.sh

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
flags="-max_total_time=$runtime -artifact_prefix=fuzzer_output/ -max_len=128"
3333

34+
3435
if [ "$jobs" != "1" ]
3536
then
3637
flags="-jobs=$jobs -workers=$jobs $flags"

tools/fuzzer/runners/nanopb_fuzzer_serverlist_test.sh

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
flags="-max_total_time=$runtime -artifact_prefix=fuzzer_output/ -max_len=128"
3333

34+
3435
if [ "$jobs" != "1" ]
3536
then
3637
flags="-jobs=$jobs -workers=$jobs $flags"

tools/fuzzer/runners/server_fuzzer.sh

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
flags="-max_total_time=$runtime -artifact_prefix=fuzzer_output/ -max_len=2048"
3333

34+
flags="$flags -dict=test/core/end2end/fuzzers/hpack.dictionary"
35+
3436
if [ "$jobs" != "1" ]
3537
then
3638
flags="-jobs=$jobs -workers=$jobs $flags"

tools/fuzzer/runners/uri_fuzzer_test.sh

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
flags="-max_total_time=$runtime -artifact_prefix=fuzzer_output/ -max_len=128"
3333

34+
3435
if [ "$jobs" != "1" ]
3536
then
3637
flags="-jobs=$jobs -workers=$jobs $flags"

0 commit comments

Comments
 (0)