Unverified Commit efeb4a31 authored by Max Dymond's avatar Max Dymond Committed by Daniel Stenberg
Browse files

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
parent 222e65fd
Loading
Loading
Loading
Loading
+14 −0
Original line number Original line Diff line number Diff line
@@ -60,6 +60,10 @@ matrix:
          compiler: gcc
          compiler: gcc
          dist: trusty
          dist: trusty
          env: T=distcheck
          env: T=distcheck
        - os: linux
          compiler: clang
          dist: trusty
          env: T=fuzzer


install:
install:
  - pip install --user cpp-coveralls
  - pip install --user cpp-coveralls
@@ -138,6 +142,16 @@ script:
             cmake .. && \
             cmake .. && \
             make)
             make)
        fi
        fi
    - |
        if [ "$T" = "fuzzer" ]; then
          export CC=clang
          export CFLAGS="-fsanitize=address"
          ./configure --disable-shared --enable-debug --enable-maintainer-mode
          make
          cd tests/fuzz
          make clean
          make check
        fi


# whitelist branches to avoid testing feature branches twice (as branch and as pull request)
# whitelist branches to avoid testing feature branches twice (as branch and as pull request)
branches:
branches:
+3 −0
Original line number Original line Diff line number Diff line
@@ -210,6 +210,9 @@ test-am:


endif
endif


fuzzer:
	@(cd tests/fuzz; $(MAKE) all)

examples:
examples:
	@(cd docs/examples; $(MAKE) check)
	@(cd docs/examples; $(MAKE) check)


+13 −8
Original line number Original line Diff line number Diff line
@@ -24,12 +24,15 @@
from __future__ import (absolute_import, division, print_function,
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
                        unicode_literals)
import os
import os
import xml.etree.ElementTree as ET
import re
import logging
import logging


log = logging.getLogger(__name__)
log = logging.getLogger(__name__)




REPLY_DATA = re.compile("<reply>\s*<data>(.*?)</data>", re.MULTILINE | re.DOTALL)


class TestData(object):
class TestData(object):
    def __init__(self, data_folder):
    def __init__(self, data_folder):
        self.data_folder = data_folder
        self.data_folder = data_folder
@@ -39,15 +42,17 @@ class TestData(object):
        filename = os.path.join(self.data_folder,
        filename = os.path.join(self.data_folder,
                                "test{0}".format(test_number))
                                "test{0}".format(test_number))


        # The user should handle the exception from failing to find the file.
        log.debug("Parsing file %s", filename)
        tree = ET.parse(filename)

        with open(filename, "rb") as f:
            contents = f.read().decode("utf-8")


        # We need the <reply><data> text.
        m = REPLY_DATA.search(contents)
        reply = tree.find("reply")
        if not m:
        data = reply.find("data")
            raise Exception("Couldn't find a <reply><data> section")


        # Return the text contents of the data
        # Left-strip the data so we don't get a newline before our data.
        return data.text
        return m.group(1).lstrip()




if __name__ == '__main__':
if __name__ == '__main__':

tests/fuzz/CMakeLists.txt

deleted100644 → 0
+0 −1
Original line number Original line Diff line number Diff line
# FIXME, probably adapt from file in ../unit
+12 −9
Original line number Original line Diff line number Diff line
@@ -30,18 +30,21 @@ AUTOMAKE_OPTIONS = foreign nostdinc
# $(top_builddir)/lib is for libcurl's generated lib/curl_config.h file
# $(top_builddir)/lib is for libcurl's generated lib/curl_config.h file
# $(top_srcdir)/lib for libcurl's lib/curl_setup.h and other "borrowed" files
# $(top_srcdir)/lib for libcurl's lib/curl_setup.h and other "borrowed" files


AM_CPPFLAGS = -I$(top_srcdir)/include        \
AM_CFLAGS = -I$(top_srcdir)/include        \
            -I$(top_builddir)/lib          \
            -I$(top_builddir)/lib          \
            -I$(top_srcdir)/lib            \
            -I$(top_srcdir)/lib            \
            -I$(top_srcdir)/tests/fuzz
            -I$(top_srcdir)/tests/fuzz


EXTRA_DIST = Makefile.inc CMakeLists.txt
LIBS = -lpthread -lstdc++ -lm


LIBS = -lpthread -lFuzzer -lstdc++ -lm
# Run e.g. "make all LIB_FUZZING_ENGINE=/path/to/libFuzzer.a"
LDFLAGS = -L/usr/lib/llvm-5.0/lib
# to link the fuzzer(s) against a real fuzzing engine.
#
# OSS-Fuzz will define its own value for LIB_FUZZING_ENGINE.
LIB_FUZZING_ENGINE ?= libstandaloneengine.a


LDADD = $(top_builddir)/lib/libcurl.la      \
LDADD = $(top_builddir)/lib/libcurl.la      \
        @LDFLAGS@ @LIBCURL_LIBS@
        $(LIB_FUZZING_ENGINE) @LDFLAGS@ @LIBCURL_LIBS@


# Makefile.inc provides neat definitions
# Makefile.inc provides neat definitions
include Makefile.inc
include Makefile.inc
@@ -50,4 +53,4 @@ checksrc:
	@PERL@ $(top_srcdir)/lib/checksrc.pl $(srcdir)/*.c
	@PERL@ $(top_srcdir)/lib/checksrc.pl $(srcdir)/*.c


noinst_PROGRAMS = $(FUZZPROGS)
noinst_PROGRAMS = $(FUZZPROGS)
noinst_LIBRARIES = $(FUZZLIBS)
 No newline at end of file
Loading