From efeb4a317616b0437a26277945bd300eaffe96d7 Mon Sep 17 00:00:00 2001 From: Max Dymond Date: Sun, 27 Aug 2017 15:57:05 +0100 Subject: ossfuzz: moving towards the ideal integration - Start with the basic code from the ossfuzz project. - Rewrite fuzz corpora to be binary files full of Type-Length-Value data, and write a glue layer in the fuzzing function to convert corpora into CURL options. - Have supporting functions to generate corpora from existing tests - Integrate with Makefile.am --- tests/curl_test_data.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'tests/curl_test_data.py') diff --git a/tests/curl_test_data.py b/tests/curl_test_data.py index bfe1287d8..21747407d 100755 --- a/tests/curl_test_data.py +++ b/tests/curl_test_data.py @@ -24,12 +24,15 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) import os -import xml.etree.ElementTree as ET +import re import logging log = logging.getLogger(__name__) +REPLY_DATA = re.compile("\s*(.*?)", re.MULTILINE | re.DOTALL) + + class TestData(object): def __init__(self, data_folder): self.data_folder = data_folder @@ -39,15 +42,17 @@ class TestData(object): filename = os.path.join(self.data_folder, "test{0}".format(test_number)) - # The user should handle the exception from failing to find the file. - tree = ET.parse(filename) + log.debug("Parsing file %s", filename) + + with open(filename, "rb") as f: + contents = f.read().decode("utf-8") - # We need the text. - reply = tree.find("reply") - data = reply.find("data") + m = REPLY_DATA.search(contents) + if not m: + raise Exception("Couldn't find a section") - # Return the text contents of the data - return data.text + # Left-strip the data so we don't get a newline before our data. + return m.group(1).lstrip() if __name__ == '__main__': -- cgit v1.2.3