Fix dictionary concatenation bug by enforcing newlines on each dictionary entry. (#125)
* Restructure the dictionary examples in order to exercise dictionary concatenation.
* Fix dictionary concatenation bug by enforcing newlines on each dictionary entry.
diff --git a/examples/BUILD b/examples/BUILD
index 4b1e0a4..02e7e93 100644
--- a/examples/BUILD
+++ b/examples/BUILD
@@ -49,7 +49,10 @@
":corpus_filegroup",
"test_corpus_dir",
],
- dicts = ["dict_dir/valid.dict"],
+ dicts = [
+ "dictionaries/valid_part1.dict",
+ "dictionaries/valid_part2.dict",
+ ],
)
cc_fuzz_test(
diff --git a/examples/dict_dir/valid.dict b/examples/dict_dir/valid.dict
deleted file mode 100755
index 681e838..0000000
--- a/examples/dict_dir/valid.dict
+++ /dev/null
@@ -1,28 +0,0 @@
-# Dictionary from Enovy
-":path"
-":method"
-":scheme"
-":status"
-":authority"
-"host"
-"keep-alive"
-":protocol"
-"set-cookie"
-"upgrade"
-"via"
-"te"
-"user-agent"
-"content-length"
-"chunked"
-"transfer-encoding"
-# Lines starting with '#' and empty lines are ignored.
-
-# Adds "blah" (w/o quotes) to the dictionary.
-kw1="blah"
-# Use \\ for backslash and \" for quotes.
-kw2="\"ac\\dc\""
-# Use \xAB for hex values
-kw3="\xF7\xF8""
-# the name of the keyword followed by '=' may be omitted:
-"foo\x0Abar"
-"ab""
diff --git a/examples/dict_dir/invalid.dict b/examples/dictionaries/invalid.dict
similarity index 100%
rename from examples/dict_dir/invalid.dict
rename to examples/dictionaries/invalid.dict
diff --git a/examples/dictionaries/valid_part1.dict b/examples/dictionaries/valid_part1.dict
new file mode 100644
index 0000000..913cbad
--- /dev/null
+++ b/examples/dictionaries/valid_part1.dict
@@ -0,0 +1,12 @@
+# This is the first part of the example dictionary.
+# Lines starting with '#' and empty lines are ignored.
+
+# Adds "blah" (w/o quotes) to the dictionary.
+kw1="blah"
+# Use \\ for backslash and \" for quotes.
+kw2="\"ac\\dc\""
+# Use \xAB for hex values
+kw3="\xF7\xF8""
+# the name of the keyword followed by '=' may be omitted:
+"foo\x0Abar"
+"ab\""
\ No newline at end of file
diff --git a/examples/dictionaries/valid_part2.dict b/examples/dictionaries/valid_part2.dict
new file mode 100755
index 0000000..799793e
--- /dev/null
+++ b/examples/dictionaries/valid_part2.dict
@@ -0,0 +1,17 @@
+# This is the second part of the example dictionary.
+":path"
+":method"
+":scheme"
+":status"
+":authority"
+"host"
+"keep-alive"
+":protocol"
+"set-cookie"
+"upgrade"
+"via"
+"te"
+"user-agent"
+"content-length"
+"chunked"
+"transfer-encoding"
diff --git a/fuzzing/tools/validate_dict.py b/fuzzing/tools/validate_dict.py
index b6cf7e5..28f9065 100644
--- a/fuzzing/tools/validate_dict.py
+++ b/fuzzing/tools/validate_dict.py
@@ -34,13 +34,13 @@
def validate_dict(dict_path, output_stream):
with open(dict_path, 'r') as dict:
for line in dict.readlines():
+ line = line.strip()
if not validate_line(line):
- print("ERROR: invalid dictionary entry \'" + line.strip() +
- "\'",
+ print("ERROR: invalid dictionary entry '%s'" % line,
file=stderr)
return False
if output_stream:
- output_stream.write(line)
+ output_stream.write(line + "\n")
return True