summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am3
-rw-r--r--configure.ac73
-rw-r--r--fuzz/Makefile.am36
-rwxr-xr-xfuzz/fuzzers.test8
-rwxr-xr-xfuzz/init-fuzzers.sh23
-rwxr-xr-xfuzz/test-fuzzers.sh33
6 files changed, 175 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index 670e7a5..5f36fd7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4,6 +4,9 @@ SUBDIRS = libcnary src include tools test
4if HAVE_CYTHON 4if HAVE_CYTHON
5SUBDIRS += cython 5SUBDIRS += cython
6endif 6endif
7if BUILD_FUZZERS
8SUBDIRS += fuzz
9endif
7 10
8docs/html: $(top_builddir)/doxygen.cfg $(top_srcdir)/include/plist/*.h 11docs/html: $(top_builddir)/doxygen.cfg $(top_srcdir)/include/plist/*.h
9 rm -rf docs 12 rm -rf docs
diff --git a/configure.ac b/configure.ac
index 1ad1341..43017bf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -156,6 +156,76 @@ case "$GLOBAL_CFLAGS" in
156 AC_DEFINE([HAVE_FVISIBILITY], [1], [Define if compiled with -fvisibility=hidden]) 156 AC_DEFINE([HAVE_FVISIBILITY], [1], [Define if compiled with -fvisibility=hidden])
157esac 157esac
158 158
159AC_ARG_WITH([fuzzers],
160 [AS_HELP_STRING([--with-fuzzers],
161 [build fuzzers and libplist with sanitizers (default is no)])],
162 [build_fuzzers=true],
163 [build_fuzzers=false])
164if test "x$build_fuzzers" = "xtrue"; then
165 AS_COMPILER_FLAG([-fsanitize=address], [
166 SANITIZER_FLAGS+=" -fsanitize=address"
167 ASAN_AVAILABLE=yes
168 ], [])
169 if test "$ASAN_AVAILABLE" = "yes"; then
170 AS_COMPILER_FLAG([-fsanitize=address -fsanitize-address-use-after-scope], [
171 SANITIZER_FLAGS+=" -fsanitize-address-use-after-scope"
172 ], [])
173 SANITIZERS+="ASAN "
174 fi
175
176 AS_COMPILER_FLAG([-fsanitize=undefined], [
177 SANITIZER_FLAGS+=" -fsanitize=undefined"
178 UBSAN_AVAILABLE=yes
179 ], [])
180
181 if test "$UBSAN_AVAILABLE" = "yes"; then
182 SANITIZERS+="UBSAN "
183 fi
184
185 if test -z "$SANITIZER_FLAGS"; then
186 AC_MSG_ERROR([compiler doesn't support -fsanitize=address nor -fsanitize=undefined])
187 fi
188
189 COVERAGE_CHECKS="trace-pc-guard trace-cmp edge"
190 for COV_CHECK in $COVERAGE_CHECKS; do
191 AS_COMPILER_FLAG([-fsanitize-coverage=$COV_CHECK], [
192 if test -z "$SAN_COV_FLAGS"; then
193 SAN_COV_FLAGS="$COV_CHECK"
194 else
195 SAN_COV_FLAGS+=",$COV_CHECK"
196 fi
197 ], [])
198 done
199 if test -n "$SAN_COV_FLAGS"; then
200 SANITIZER_FLAGS+=" -fsanitize-coverage=$SAN_COV_FLAGS"
201 else
202 AC_MSG_WARN([No sanitizer coverage supported by compiler])
203 fi
204
205 CFLAGS="-O1"
206
207 AS_COMPILER_FLAG([-fno-omit-frame-pointer], [
208 CFLAGS+=" -fno-omit-frame-pointer"
209 ], [])
210
211 AS_COMPILER_FLAG([-gline-tables-only], [
212 CFLAGS+=" -gline-tables-only"
213 ],
214 [
215 CFLAGS+=" -g"
216 ])
217
218 CFLAGS+=" -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION"
219 CFLAGS+=" $SANITIZER_FLAGS"
220 CXXFLAGS="$CFLAGS -std=c++11"
221 EXTRA_CONF+=" Build fuzzers ...........: yes
222"
223 EXTRA_CONF+=" Enabled sanitizers ......: $SANITIZERS
224"
225 AS_COMPILER_FLAGS(TEST_CFLAGS, [$CFLAGS])
226fi
227AM_CONDITIONAL([BUILD_FUZZERS],[test "x$build_fuzzers" = "xtrue"])
228
159m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) 229m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
160 230
161AC_OUTPUT([ 231AC_OUTPUT([
@@ -168,6 +238,7 @@ include/Makefile
168tools/Makefile 238tools/Makefile
169cython/Makefile 239cython/Makefile
170test/Makefile 240test/Makefile
241fuzz/Makefile
171doxygen.cfg 242doxygen.cfg
172]) 243])
173 244
@@ -178,7 +249,7 @@ Configuration for $PACKAGE $VERSION:
178 Install prefix ..........: $prefix 249 Install prefix ..........: $prefix
179 Debug code ..............: $debug 250 Debug code ..............: $debug
180 Python bindings .........: $cython_python_bindings 251 Python bindings .........: $cython_python_bindings
181 252$EXTRA_CONF
182 Now type 'make' to build $PACKAGE $VERSION, 253 Now type 'make' to build $PACKAGE $VERSION,
183 and then 'make install' for installation. 254 and then 'make install' for installation.
184" 255"
diff --git a/fuzz/Makefile.am b/fuzz/Makefile.am
new file mode 100644
index 0000000..b9798f9
--- /dev/null
+++ b/fuzz/Makefile.am
@@ -0,0 +1,36 @@
1if BUILD_FUZZERS
2
3libFuzzer.a: Fuzzer/build.sh
4 @echo "Building $@"
5 @./Fuzzer/build.sh
6
7Fuzzer/build.sh: LIBFUZZER_SRC
8
9LIBFUZZER_SRC:
10 @if test -d Fuzzer ; then \
11 if test -d Fuzzer/.git ; then \
12 echo Making sure libFuzzer source tree is up-to-date... ; \
13 cd Fuzzer && git checkout . && git pull && cd .. ; \
14 fi \
15 else \
16 echo Checking out libFuzzer source code... ; \
17 git clone https://chromium.googlesource.com/chromium/llvm-project/llvm/lib/Fuzzer ; \
18 fi
19
20CLEANFILES = libFuzzer.a
21
22noinst_PROGRAMS = xplist_fuzzer bplist_fuzzer
23
24xplist_fuzzer_SOURCES = xplist_fuzzer.cc
25xplist_fuzzer_LDFLAGS = -static
26xplist_fuzzer_LDADD = $(top_builddir)/src/libplist.la libFuzzer.a
27
28bplist_fuzzer_SOURCES = bplist_fuzzer.cc
29bplist_fuzzer_LDFLAGS = -static
30bplist_fuzzer_LDADD = $(top_builddir)/src/libplist.la libFuzzer.a
31
32TESTS = fuzzers.test
33
34EXTRA_DIST = bplist.dict xplist.dict init-fuzzers.sh test-fuzzers.sh fuzzers.test
35
36endif
diff --git a/fuzz/fuzzers.test b/fuzz/fuzzers.test
new file mode 100755
index 0000000..dd3fb08
--- /dev/null
+++ b/fuzz/fuzzers.test
@@ -0,0 +1,8 @@
1## -*- sh -*-
2
3set -e
4
5./init-fuzzers.sh
6
7./test-fuzzers.sh
8
diff --git a/fuzz/init-fuzzers.sh b/fuzz/init-fuzzers.sh
new file mode 100755
index 0000000..e48baa8
--- /dev/null
+++ b/fuzz/init-fuzzers.sh
@@ -0,0 +1,23 @@
1#!/bin/sh
2
3CURDIR=`pwd`
4FUZZDIR=`dirname $0`
5
6cd ${FUZZDIR}
7
8if ! test -x xplist_fuzzer || ! test -x bplist_fuzzer; then
9 echo "ERROR: you need to build the fuzzers first."
10 cd ${CURDIR}
11 exit 1
12fi
13
14mkdir -p xplist-input
15cp ../test/data/*.plist xplist-input/
16./xplist_fuzzer -merge=1 xplist-input crashes leaks -dict=xplist.dict
17
18mkdir -p bplist-input
19cp ../test/data/*.bplist bplist-input/
20./bplist_fuzzer -merge=1 bplist-input crashes leaks -dict=bplist.dict
21
22cd ${CURDIR}
23exit 0
diff --git a/fuzz/test-fuzzers.sh b/fuzz/test-fuzzers.sh
new file mode 100755
index 0000000..5c758c4
--- /dev/null
+++ b/fuzz/test-fuzzers.sh
@@ -0,0 +1,33 @@
1#!/bin/sh
2
3CURDIR=`pwd`
4FUZZDIR=`dirname $0`
5
6cd ${FUZZDIR}
7
8if ! test -x xplist_fuzzer || ! test -x bplist_fuzzer; then
9 echo "ERROR: you need to build the fuzzers first."
10 cd ${CURDIR}
11 exit 1
12fi
13
14if ! test -d xplist-input || ! test -d bplist-input; then
15 echo "ERROR: fuzzer corpora directories are not present. Did you run init-fuzzers.sh ?"
16 cd ${CURDIR}
17 exit 1
18fi
19
20echo "### TESTING xplist_fuzzer ###"
21if ! ./xplist_fuzzer xplist-input -dict=xplist.dict -runs=10000; then
22 cd ${CURDIR}
23 exit 1
24fi
25
26echo "### TESTING bplist_fuzzer ###"
27if ! ./bplist_fuzzer bplist-input -dict=bplist.dict -runs=10000; then
28 cd ${CURDIR}
29 exit 1
30fi
31
32cd ${CURDIR}
33exit 0