File size: 5,910 Bytes
6baed57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
AUTOMAKE_OPTIONS = -Wno-syntax
EXTRA_PROGRAMS = genSeed \
		 api html lint reader regexp schema uri valid xinclude \
		 xml xpath
check_PROGRAMS = testFuzzer
EXTRA_DIST = html.dict regexp.dict schema.dict xml.dict xpath.dict \
	     static_seed/uri static_seed/regexp fuzz.h
CLEANFILES = $(EXTRA_PROGRAMS)
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
DEPENDENCIES = $(top_builddir)/libxml2.la
LDADD = $(top_builddir)/libxml2.la

XML_MAX_LEN = 80000
# Single quotes to avoid wildcard expansion by the shell
XML_SEED_CORPUS_SRC = \
    '$(top_srcdir)/test/*' \
    '$(top_srcdir)/test/errors/*.xml' \
    '$(top_srcdir)/test/errors10/*.xml' \
    '$(top_srcdir)/test/namespaces/*' \
    '$(top_srcdir)/test/recurse/*.xml' \
    '$(top_srcdir)/test/SVG/*.xml' \
    '$(top_srcdir)/test/valid/*.xml' \
    '$(top_srcdir)/test/VC/*' \
    '$(top_srcdir)/test/VCM/*' \
    '$(top_srcdir)/test/XInclude/docs/*' \
    '$(top_srcdir)/test/XInclude/without-reader/*' \
    '$(top_srcdir)/test/xmlid/*'

testFuzzer_SOURCES = testFuzzer.c fuzz.c

.PHONY: corpus clean-corpus

corpus: seed/html.stamp seed/lint.stamp seed/reader.stamp seed/regexp.stamp \
    seed/schema.stamp seed/uri.stamp seed/valid.stamp seed/xinclude.stamp \
    seed/xml.stamp seed/xpath.stamp

check-local: corpus
	./testFuzzer$(EXEEXT)

clean-corpus:
	rm -rf seed

clean-local: clean-corpus

# Seed corpus

genSeed_SOURCES = genSeed.c fuzz.c

# XML fuzzer

seed/xml.stamp: genSeed$(EXEEXT)
	@mkdir -p seed/xml
	./genSeed$(EXEEXT) xml $(XML_SEED_CORPUS_SRC)
	@touch seed/xml.stamp

xml_SOURCES = xml.c fuzz.c
xml_LDFLAGS = $(AM_LDFLAGS) -fsanitize=fuzzer

fuzz-xml: xml$(EXEEXT) seed/xml.stamp
	@mkdir -p corpus/xml
	./xml$(EXEEXT) \
	    -dict=$(srcdir)/xml.dict \
	    -max_len=$(XML_MAX_LEN) \
	    $$XML_FUZZ_OPTIONS \
	    corpus/xml seed/xml

# DTD validation fuzzer

seed/valid.stamp: genSeed$(EXEEXT)
	@mkdir -p seed/valid
	./genSeed$(EXEEXT) valid $(XML_SEED_CORPUS_SRC)
	@touch seed/valid.stamp

valid_SOURCES = valid.c fuzz.c
valid_LDFLAGS = $(AM_LDFLAGS) -fsanitize=fuzzer

fuzz-valid: valid$(EXEEXT) seed/valid.stamp
	@mkdir -p corpus/valid
	./valid$(EXEEXT) \
	    -dict=$(srcdir)/xml.dict \
	    -max_len=$(XML_MAX_LEN) \
	    $$XML_FUZZ_OPTIONS \
	    corpus/valid seed/valid

# XInclude fuzzer

seed/xinclude.stamp: genSeed$(EXEEXT)
	@mkdir -p seed/xinclude
	./genSeed$(EXEEXT) xinclude $(XML_SEED_CORPUS_SRC)
	@touch seed/xinclude.stamp

xinclude_SOURCES = xinclude.c fuzz.c
xinclude_LDFLAGS = $(AM_LDFLAGS) -fsanitize=fuzzer

fuzz-xinclude: xinclude$(EXEEXT) seed/xinclude.stamp
	@mkdir -p corpus/xinclude
	./xinclude$(EXEEXT) \
	    -dict=$(srcdir)/xml.dict \
	    -max_len=$(XML_MAX_LEN) \
	    $$XML_FUZZ_OPTIONS \
	    corpus/xinclude seed/xinclude

# HTML fuzzer

seed/html.stamp: genSeed$(EXEEXT)
	@mkdir -p seed/html
	./genSeed$(EXEEXT) html '$(top_srcdir)/test/HTML/*'
	@touch seed/html.stamp

html_SOURCES = html.c fuzz.c
html_LDFLAGS = $(AM_LDFLAGS) -fsanitize=fuzzer

fuzz-html: html$(EXEEXT) seed/html.stamp
	@mkdir -p corpus/html
	./html$(EXEEXT) \
	    -dict=$(srcdir)/html.dict \
	    -max_len=1000000 \
	    $$XML_FUZZ_OPTIONS \
	    corpus/html seed/html

# Reader fuzzer

seed/reader.stamp: genSeed$(EXEEXT)
	@mkdir -p seed/reader
	./genSeed$(EXEEXT) reader $(XML_SEED_CORPUS_SRC)
	@touch seed/reader.stamp

reader_SOURCES = reader.c fuzz.c
reader_LDFLAGS = $(AM_LDFLAGS) -fsanitize=fuzzer

fuzz-reader: reader$(EXEEXT) seed/reader.stamp
	@mkdir -p corpus/reader
	./reader$(EXEEXT) \
	    -dict=$(srcdir)/xml.dict \
	    -max_len=$(XML_MAX_LEN) \
	    $$XML_FUZZ_OPTIONS \
	    corpus/reader seed/reader

# xmllint fuzzer

seed/lint.stamp: genSeed$(EXEEXT)
	@mkdir -p seed/lint
	./genSeed$(EXEEXT) lint $(XML_SEED_CORPUS_SRC)
	@touch seed/lint.stamp

lint_SOURCES = lint.c fuzz.c ../xmllint.c ../shell.c
lint_LDFLAGS = -fsanitize=fuzzer

fuzz-lint: lint$(EXEEXT) seed/lint.stamp
	@mkdir -p corpus/lint
	./lint$(EXEEXT) \
	    -dict=$(srcdir)/xml.dict \
	    -max_len=$(XML_MAX_LEN) \
	    $$XML_FUZZ_OPTIONS \
	    corpus/lint seed/lint

# API fuzzer

api_SOURCES = api.c fuzz.c
api_LDFLAGS = -fsanitize=fuzzer

fuzz-api: api$(EXEEXT)
	@mkdir -p corpus/api
	./api$(EXEEXT) \
	    -max_len=100 \
	    $$XML_FUZZ_OPTIONS \
	    corpus/api

# Regexp fuzzer

seed/regexp.stamp:
	@mkdir -p seed/regexp
	cp -r $(srcdir)/static_seed/regexp seed
	@touch seed/regexp.stamp

regexp_SOURCES = regexp.c fuzz.c
regexp_LDFLAGS = $(AM_LDFLAGS) -fsanitize=fuzzer

fuzz-regexp: regexp$(EXEEXT) seed/regexp.stamp
	@mkdir -p corpus/regexp
	./regexp$(EXEEXT) \
	    -dict=$(srcdir)/regexp.dict \
	    -max_len=200 \
	    $$XML_FUZZ_OPTIONS \
	    corpus/regexp seed/regexp

# URI fuzzer

seed/uri.stamp:
	@mkdir -p seed/uri
	cp -r $(srcdir)/static_seed/uri seed
	@touch seed/uri.stamp

uri_SOURCES = uri.c fuzz.c
uri_LDFLAGS = $(AM_LDFLAGS) -fsanitize=fuzzer

fuzz-uri: uri$(EXEEXT) seed/uri.stamp
	@mkdir -p corpus/uri
	./uri$(EXEEXT) \
	    -max_len=10000 \
	    $$XML_FUZZ_OPTIONS \
	    corpus/uri seed/uri

# XML Schema fuzzer

seed/schema.stamp: genSeed$(EXEEXT)
	@mkdir -p seed/schema
	./genSeed$(EXEEXT) schema '$(top_srcdir)/test/schemas/*.xsd'
	@touch seed/schema.stamp

schema_SOURCES = schema.c fuzz.c
schema_LDFLAGS = $(AM_LDFLAGS) -fsanitize=fuzzer

fuzz-schema: schema$(EXEEXT) seed/schema.stamp
	@mkdir -p corpus/schema
	./schema$(EXEEXT) \
	    -dict=$(srcdir)/schema.dict \
	    -max_len=$(XML_MAX_LEN) \
	    $$XML_FUZZ_OPTIONS \
	    corpus/schema seed/schema

# XPath fuzzer

seed/xpath.stamp: genSeed$(EXEEXT)
	@mkdir -p seed/xpath
	./genSeed$(EXEEXT) xpath '$(top_srcdir)/test/XPath'
	@touch seed/xpath.stamp

xpath_SOURCES = xpath.c fuzz.c
xpath_LDFLAGS = $(AM_LDFLAGS) -fsanitize=fuzzer

fuzz-xpath: xpath$(EXEEXT) seed/xpath.stamp
	@mkdir -p corpus/xpath
	./xpath$(EXEEXT) \
	    -dict=$(srcdir)/xpath.dict \
	    -max_len=10000 \
	    $$XML_FUZZ_OPTIONS \
	    corpus/xpath seed/xpath