summaryrefslogtreecommitdiff
path: root/fuzz/Makefile.am
blob: a286f86754fc75fd5d5c755259cfcdd671cee015 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
EXTRA_PROGRAMS = html regexp uri xml xmlSeed
check_PROGRAMS = testFuzzer
CLEANFILES = $(EXTRA_PROGRAMS)
AM_CPPFLAGS = -I$(top_srcdir)/include
DEPENDENCIES = $(top_builddir)/libxml2.la
LDADD = $(STATIC_BINARIES) $(top_builddir)/libxml2.la $(THREAD_LIBS) $(Z_LIBS) $(LZMA_LIBS) $(ICONV_LIBS) $(M_LIBS) $(WIN32_EXTRA_LIBADD)

PARSER_FUZZER_MAX_LEN = 100000
XML_SEED_CORPUS_SRC = \
    $(top_srcdir)/test/* \
    $(top_srcdir)/test/errors/*.xml \
    $(top_srcdir)/test/errors10/*.xml \
    $(top_srcdir)/test/namespaces/* \
    $(top_srcdir)/test/valid/*.xml \
    $(top_srcdir)/test/xmlid/* \
    $(top_srcdir)/test/VC/* \
    $(top_srcdir)/test/VCM/*

xmlSeed_SOURCES = xmlSeed.c fuzz.c

seed/xml.stamp: xmlSeed$(EXEEXT)
	@mkdir -p seed/xml
	@for i in $(XML_SEED_CORPUS_SRC); do \
	    if [ -f $$i ]; then \
	        echo Processing seed $$i; \
                base=$$(basename $$i) \
	        outfile=$(abs_builddir)/seed/xml/$$base; \
                pushd $$(dirname $$i) >/dev/null; \
	        $(abs_builddir)/xmlSeed$(EXEEXT) $$base > $$outfile; \
                popd >/dev/null; \
	        if [ "$$(wc -c < $$outfile)" -gt $(PARSER_FUZZER_MAX_LEN) ]; then \
	            rm $$outfile; \
	        fi; \
	    fi; \
	done
	@touch seed/xml.stamp

testFuzzer_SOURCES = testFuzzer.c fuzz.c

tests: testFuzzer$(EXEEXT)
	@echo "## Running fuzzer tests"
	@./testFuzzer$(EXEEXT)

xml_SOURCES = xml.c fuzz.c
xml_LDFLAGS = -fsanitize=fuzzer

fuzz-xml: xml$(EXEEXT) seed/xml.stamp
	@mkdir -p corpus/xml
	./xml$(EXEEXT) \
	    -dict=xml.dict \
	    -max_len=$(PARSER_FUZZER_MAX_LEN) \
	    -timeout=20 \
	    corpus/xml seed/xml

html_SOURCES = html.c fuzz.c
html_LDFLAGS = -fsanitize=fuzzer

fuzz-html: html$(EXEEXT)
	@mkdir -p corpus/html
	./html$(EXEEXT) \
	    -dict=html.dict \
	    -max_len=1000000 \
	    -timeout=20 \
	    corpus/html $(top_srcdir)/test/HTML

regexp_SOURCES = regexp.c fuzz.c
regexp_LDFLAGS = -fsanitize=fuzzer

fuzz-regexp: regexp$(EXEEXT)
	@mkdir -p corpus/regexp
	./regexp$(EXEEXT) \
	    -dict=regexp.dict \
	    -max_len=10000 \
	    -timeout=20 \
	    corpus/regexp $(srcdir)/seed/regexp

uri_SOURCES = uri.c fuzz.c
uri_LDFLAGS = -fsanitize=fuzzer

fuzz-uri: uri$(EXEEXT)
	@mkdir -p corpus/uri
	./uri$(EXEEXT) \
	    -max_len=10000 \
	    -timeout=2 \
	    corpus/uri $(srcdir)/seed/uri