aboutsummaryrefslogtreecommitdiff
path: root/tests/fuzz/generate_corpus.py
diff options
context:
space:
mode:
authorMax Dymond <cmeister2@gmail.com>2017-09-11 20:51:58 +0100
committerDaniel Stenberg <daniel@haxx.se>2017-09-18 23:23:13 +0200
commitc73ebb85374164515eb9df6d619a5822b6568599 (patch)
tree12de79815f33cece38fd77ce9ed6443cdf247afa /tests/fuzz/generate_corpus.py
parentbec50cc285995b18d57e5e5caf17e33100795f09 (diff)
ossfuzz: changes before merging the generated corpora
Before merging in the oss-fuzz corpora from Google, there are some changes to the fuzzer. - Add a read corpus script, to display corpus files nicely. - Change the behaviour of the fuzzer so that TLV parse failures all now go down the same execution paths, which should reduce the size of the corpora. - Make unknown TLVs a failure to parse, which should decrease the size of the corpora as well. Closes #1881
Diffstat (limited to 'tests/fuzz/generate_corpus.py')
-rwxr-xr-xtests/fuzz/generate_corpus.py48
1 files changed, 2 insertions, 46 deletions
diff --git a/tests/fuzz/generate_corpus.py b/tests/fuzz/generate_corpus.py
index 04c799926..cffdd37bf 100755
--- a/tests/fuzz/generate_corpus.py
+++ b/tests/fuzz/generate_corpus.py
@@ -4,7 +4,7 @@
import argparse
import logging
-import struct
+import corpus
import sys
sys.path.append("..")
import curl_test_data
@@ -15,7 +15,7 @@ def generate_corpus(options):
td = curl_test_data.TestData("../data")
with open(options.output, "wb") as f:
- enc = TLVEncoder(f)
+ enc = corpus.TLVEncoder(f)
# Write the URL to the file.
enc.write_string(enc.TYPE_URL, options.url)
@@ -61,50 +61,6 @@ def generate_corpus(options):
return ScriptRC.SUCCESS
-class TLVEncoder(object):
- TYPE_URL = 1
- TYPE_RSP1 = 2
- TYPE_USERNAME = 3
- TYPE_PASSWORD = 4
- TYPE_POSTFIELDS = 5
- TYPE_HEADER = 6
- TYPE_COOKIE = 7
- TYPE_UPLOAD1 = 8
- TYPE_RANGE = 9
- TYPE_CUSTOMREQUEST = 10
- TYPE_MAIL_RECIPIENT = 11
- TYPE_MAIL_FROM = 12
-
- def __init__(self, output):
- self.output = output
-
- def write_string(self, tlv_type, wstring):
- data = wstring.encode("utf-8")
- self.write_tlv(tlv_type, len(data), data)
-
- def write_bytes(self, tlv_type, bytedata):
- self.write_tlv(tlv_type, len(bytedata), bytedata)
-
- def maybe_write_string(self, tlv_type, wstring):
- if wstring is not None:
- self.write_string(tlv_type, wstring)
-
- def write_tlv(self, tlv_type, tlv_length, tlv_data=None):
- log.debug("Writing TLV %d, length %d, data %r",
- tlv_type,
- tlv_length,
- tlv_data)
-
- data = struct.pack("!H", tlv_type)
- self.output.write(data)
-
- data = struct.pack("!L", tlv_length)
- self.output.write(data)
-
- if tlv_data:
- self.output.write(tlv_data)
-
-
def get_options():
parser = argparse.ArgumentParser()
parser.add_argument("--output", required=True)