From 134a6b6ffda49e05643fb736d6914f4b10aa07d8 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 18 Apr 2016 08:14:20 -0700 Subject: Dictionary support for fuzzers --- tools/codegen/core/gen_static_metadata.py | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tools/codegen/core/gen_static_metadata.py') diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index b4ba02bbe5..ad73a5e357 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -205,6 +205,7 @@ all_elems = sorted(list(all_elems), key=mangle) args = sys.argv[1:] H = None C = None +D = None if args: if 'header' in args: H = sys.stdout @@ -214,11 +215,17 @@ if args: C = sys.stdout else: C = open('/dev/null', 'w') + if 'dictionary' in args: + D = sys.stdout + else: + D = open('/dev/null', 'w') else: H = open(os.path.join( os.path.dirname(sys.argv[0]), '../../../src/core/lib/transport/static_metadata.h'), 'w') C = open(os.path.join( os.path.dirname(sys.argv[0]), '../../../src/core/lib/transport/static_metadata.c'), 'w') + D = open(os.path.join( + os.path.dirname(sys.argv[0]), '../../../test/core/end2end/fuzzers/hpack.dictionary'), 'w') # copy-paste copyright notice from this file with open(sys.argv[0]) as my_source: @@ -235,6 +242,27 @@ with open(sys.argv[0]) as my_source: copyright.append(line) put_banner([H,C], [line[2:].rstrip() for line in copyright]) + +hex_bytes = [ord(c) for c in "abcdefABCDEF0123456789"] + + +def esc_c(line): + out = "\"" + last_was_hex = False + for c in line: + if 32 <= c < 127: + if c in hex_bytes and last_was_hex: + out += "\"\"" + if c != ord('"'): + out += chr(c) + else: + out += "\\\"" + last_was_hex = False + else: + out += "\\x%02x" % c + last_was_hex = True + return out + "\"" + put_banner([H,C], """WARNING: Auto-generated code. @@ -263,6 +291,10 @@ print >>H print >>C, 'grpc_mdstr grpc_static_mdstr_table[GRPC_STATIC_MDSTR_COUNT];' print >>C +print >>D, '# hpack fuzzing dictionary' +for i, elem in enumerate(all_strs): + print >>D, 'kw%d=%s' % (i, esc_c([len(elem)] + [ord(c) for c in elem])) + print >>H, '#define GRPC_STATIC_MDELEM_COUNT %d' % len(all_elems) print >>H, 'extern grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT];' print >>H, 'extern uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT];' -- cgit v1.2.3 From 69b6d4ef621ab1fe9c7ca7f12b9e0c64d33d5fdb Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 18 Apr 2016 15:08:14 -0700 Subject: Better dictionary --- test/core/end2end/fuzzers/hpack.dictionary | 180 ++++++++++++++--------------- tools/codegen/core/gen_static_metadata.py | 11 +- 2 files changed, 93 insertions(+), 98 deletions(-) (limited to 'tools/codegen/core/gen_static_metadata.py') diff --git a/test/core/end2end/fuzzers/hpack.dictionary b/test/core/end2end/fuzzers/hpack.dictionary index 185048600f..78c4fa2403 100644 --- a/test/core/end2end/fuzzers/hpack.dictionary +++ b/test/core/end2end/fuzzers/hpack.dictionary @@ -1,91 +1,91 @@ # hpack fuzzing dictionary -kw0="\x01""0" -kw1="\x01""1" -kw2="\x01""2" -kw3="\x03""200" -kw4="\x03""204" -kw5="\x03""206" -kw6="\x03""304" -kw7="\x03""400" -kw8="\x03""404" -kw9="\x03""500" -kw10="\x06""accept" -kw11="\x0e""accept-charset" -kw12="\x0f""accept-encoding" -kw13="\x0f""accept-language" -kw14="\x0d""accept-ranges" -kw15="\x1b""access-control-allow-origin" -kw16="\x03""age" -kw17="\x05""allow" -kw18="\x10""application/grpc" -kw19="\x0a:authority" -kw20="\x0d""authorization" -kw21="\x0d""cache-control" -kw22="\x0a""census-bin" -kw23="\x11""census-binary-bin" -kw24="\x13""content-disposition" -kw25="\x10""content-encoding" -kw26="\x10""content-language" -kw27="\x0e""content-length" -kw28="\x10""content-location" -kw29="\x0d""content-range" -kw30="\x0c""content-type" -kw31="\x06""cookie" -kw32="\x04""date" -kw33="\x07""deflate" -kw34="\x0c""deflate,gzip" -kw35="\x00" -kw36="\x04""etag" -kw37="\x06""expect" -kw38="\x07""expires" -kw39="\x04""from" -kw40="\x03GET" -kw41="\x04grpc" -kw42="\x14grpc-accept-encoding" -kw43="\x0dgrpc-encoding" -kw44="\x1egrpc-internal-encoding-request" -kw45="\x0cgrpc-message" -kw46="\x0bgrpc-status" -kw47="\x0cgrpc-timeout" -kw48="\x04gzip" -kw49="\x0dgzip, deflate" -kw50="\x04host" -kw51="\x04http" -kw52="\x05https" -kw53="\x08identity" -kw54="\x10identity,deflate" -kw55="\x15identity,deflate,gzip" -kw56="\x0didentity,gzip" -kw57="\x08if-match" -kw58="\x11if-modified-since" -kw59="\x0dif-none-match" -kw60="\x08if-range" -kw61="\x13if-unmodified-since" -kw62="\x0dlast-modified" -kw63="\x04link" -kw64="\x08location" -kw65="\x0cmax-forwards" -kw66="\x07:method" -kw67="\x05:path" -kw68="\x04POST" -kw69="\x12proxy-authenticate" -kw70="\x13proxy-authorization" -kw71="\x03PUT" -kw72="\x05range" -kw73="\x07referer" -kw74="\x07refresh" -kw75="\x0bretry-after" -kw76="\x07:scheme" -kw77="\x06server" -kw78="\x0aset-cookie" -kw79="\x01/" -kw80="\x0b/index.html" -kw81="\x07:status" -kw82="\x19strict-transport-security" -kw83="\x02te" -kw84="\x08trailers" -kw85="\x11transfer-encoding" -kw86="\x0auser-agent" -kw87="\x04vary" -kw88="\x03via" -kw89="\x10www-authenticate" +"\x010" +"\x011" +"\x012" +"\x03200" +"\x03204" +"\x03206" +"\x03304" +"\x03400" +"\x03404" +"\x03500" +"\x06accept" +"\x0Eaccept-charset" +"\x0Faccept-encoding" +"\x0Faccept-language" +"\x0Daccept-ranges" +"\x1Baccess-control-allow-origin" +"\x03age" +"\x05allow" +"\x10application/grpc" +"\x0A:authority" +"\x0Dauthorization" +"\x0Dcache-control" +"\x0Acensus-bin" +"\x11census-binary-bin" +"\x13content-disposition" +"\x10content-encoding" +"\x10content-language" +"\x0Econtent-length" +"\x10content-location" +"\x0Dcontent-range" +"\x0Ccontent-type" +"\x06cookie" +"\x04date" +"\x07deflate" +"\x0Cdeflate,gzip" +"\x00" +"\x04etag" +"\x06expect" +"\x07expires" +"\x04from" +"\x03GET" +"\x04grpc" +"\x14grpc-accept-encoding" +"\x0Dgrpc-encoding" +"\x1Egrpc-internal-encoding-request" +"\x0Cgrpc-message" +"\x0Bgrpc-status" +"\x0Cgrpc-timeout" +"\x04gzip" +"\x0Dgzip, deflate" +"\x04host" +"\x04http" +"\x05https" +"\x08identity" +"\x10identity,deflate" +"\x15identity,deflate,gzip" +"\x0Didentity,gzip" +"\x08if-match" +"\x11if-modified-since" +"\x0Dif-none-match" +"\x08if-range" +"\x13if-unmodified-since" +"\x0Dlast-modified" +"\x04link" +"\x08location" +"\x0Cmax-forwards" +"\x07:method" +"\x05:path" +"\x04POST" +"\x12proxy-authenticate" +"\x13proxy-authorization" +"\x03PUT" +"\x05range" +"\x07referer" +"\x07refresh" +"\x0Bretry-after" +"\x07:scheme" +"\x06server" +"\x0Aset-cookie" +"\x01/" +"\x0B/index.html" +"\x07:status" +"\x19strict-transport-security" +"\x02te" +"\x08trailers" +"\x11transfer-encoding" +"\x0Auser-agent" +"\x04vary" +"\x03via" +"\x10www-authenticate" diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index ad73a5e357..e7b9c35808 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -246,21 +246,16 @@ with open(sys.argv[0]) as my_source: hex_bytes = [ord(c) for c in "abcdefABCDEF0123456789"] -def esc_c(line): +def esc_dict(line): out = "\"" - last_was_hex = False for c in line: if 32 <= c < 127: - if c in hex_bytes and last_was_hex: - out += "\"\"" if c != ord('"'): out += chr(c) else: out += "\\\"" - last_was_hex = False else: - out += "\\x%02x" % c - last_was_hex = True + out += "\\x%02X" % c return out + "\"" put_banner([H,C], @@ -293,7 +288,7 @@ print >>C print >>D, '# hpack fuzzing dictionary' for i, elem in enumerate(all_strs): - print >>D, 'kw%d=%s' % (i, esc_c([len(elem)] + [ord(c) for c in elem])) + print >>D, '%s' % (esc_dict([len(elem)] + [ord(c) for c in elem])) print >>H, '#define GRPC_STATIC_MDELEM_COUNT %d' % len(all_elems) print >>H, 'extern grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT];' -- cgit v1.2.3 From 942568bc9d7f606a24c2f5f1cb922c3c3c57be9c Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 18 Apr 2016 22:19:00 -0700 Subject: Better dictionary --- test/core/end2end/fuzzers/hpack.dictionary | 79 ++++++++++++++++++++++++++++++ tools/codegen/core/gen_static_metadata.py | 3 ++ 2 files changed, 82 insertions(+) (limited to 'tools/codegen/core/gen_static_metadata.py') diff --git a/test/core/end2end/fuzzers/hpack.dictionary b/test/core/end2end/fuzzers/hpack.dictionary index 78c4fa2403..b081368ff6 100644 --- a/test/core/end2end/fuzzers/hpack.dictionary +++ b/test/core/end2end/fuzzers/hpack.dictionary @@ -89,3 +89,82 @@ "\x04vary" "\x03via" "\x10www-authenticate" +"\x00\x0Eaccept-charset\x00" +"\x00\x06accept\x00" +"\x00\x0Faccept-encoding\x00" +"\x00\x0Faccept-encoding\x0Dgzip, deflate" +"\x00\x0Faccept-language\x00" +"\x00\x0Daccept-ranges\x00" +"\x00\x1Baccess-control-allow-origin\x00" +"\x00\x03age\x00" +"\x00\x05allow\x00" +"\x00\x0A:authority\x00" +"\x00\x0Dauthorization\x00" +"\x00\x0Dcache-control\x00" +"\x00\x13content-disposition\x00" +"\x00\x10content-encoding\x00" +"\x00\x10content-language\x00" +"\x00\x0Econtent-length\x00" +"\x00\x10content-location\x00" +"\x00\x0Dcontent-range\x00" +"\x00\x0Ccontent-type\x10application/grpc" +"\x00\x0Ccontent-type\x00" +"\x00\x06cookie\x00" +"\x00\x04date\x00" +"\x00\x04etag\x00" +"\x00\x06expect\x00" +"\x00\x07expires\x00" +"\x00\x04from\x00" +"\x00\x14grpc-accept-encoding\x07deflate" +"\x00\x14grpc-accept-encoding\x0Cdeflate,gzip" +"\x00\x14grpc-accept-encoding\x04gzip" +"\x00\x14grpc-accept-encoding\x08identity" +"\x00\x14grpc-accept-encoding\x10identity,deflate" +"\x00\x14grpc-accept-encoding\x15identity,deflate,gzip" +"\x00\x14grpc-accept-encoding\x0Didentity,gzip" +"\x00\x0Dgrpc-encoding\x07deflate" +"\x00\x0Dgrpc-encoding\x04gzip" +"\x00\x0Dgrpc-encoding\x08identity" +"\x00\x0Bgrpc-status\x010" +"\x00\x0Bgrpc-status\x011" +"\x00\x0Bgrpc-status\x012" +"\x00\x04host\x00" +"\x00\x08if-match\x00" +"\x00\x11if-modified-since\x00" +"\x00\x0Dif-none-match\x00" +"\x00\x08if-range\x00" +"\x00\x13if-unmodified-since\x00" +"\x00\x0Dlast-modified\x00" +"\x00\x04link\x00" +"\x00\x08location\x00" +"\x00\x0Cmax-forwards\x00" +"\x00\x07:method\x03GET" +"\x00\x07:method\x04POST" +"\x00\x07:method\x03PUT" +"\x00\x05:path\x01/" +"\x00\x05:path\x0B/index.html" +"\x00\x12proxy-authenticate\x00" +"\x00\x13proxy-authorization\x00" +"\x00\x05range\x00" +"\x00\x07referer\x00" +"\x00\x07refresh\x00" +"\x00\x0Bretry-after\x00" +"\x00\x07:scheme\x04grpc" +"\x00\x07:scheme\x04http" +"\x00\x07:scheme\x05https" +"\x00\x06server\x00" +"\x00\x0Aset-cookie\x00" +"\x00\x07:status\x03200" +"\x00\x07:status\x03204" +"\x00\x07:status\x03206" +"\x00\x07:status\x03304" +"\x00\x07:status\x03400" +"\x00\x07:status\x03404" +"\x00\x07:status\x03500" +"\x00\x19strict-transport-security\x00" +"\x00\x02te\x08trailers" +"\x00\x11transfer-encoding\x00" +"\x00\x0Auser-agent\x00" +"\x00\x04vary\x00" +"\x00\x03via\x00" +"\x00\x10www-authenticate\x00" diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index e7b9c35808..b38555e355 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -289,6 +289,9 @@ print >>C print >>D, '# hpack fuzzing dictionary' for i, elem in enumerate(all_strs): print >>D, '%s' % (esc_dict([len(elem)] + [ord(c) for c in elem])) +for i, elem in enumerate(all_elems): + print >>D, '%s' % (esc_dict([0, len(elem[0])] + [ord(c) for c in elem[0]] + + [len(elem[1])] + [ord(c) for c in elem[1]])) print >>H, '#define GRPC_STATIC_MDELEM_COUNT %d' % len(all_elems) print >>H, 'extern grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT];' -- cgit v1.2.3