diff options
| -rw-r--r-- | Makefile.am | 3 | ||||
| -rw-r--r-- | configure.ac | 73 | ||||
| -rw-r--r-- | fuzz/Makefile.am | 36 | ||||
| -rwxr-xr-x | fuzz/fuzzers.test | 8 | ||||
| -rwxr-xr-x | fuzz/init-fuzzers.sh | 23 | ||||
| -rwxr-xr-x | fuzz/test-fuzzers.sh | 33 |
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 | |||
| 4 | if HAVE_CYTHON | 4 | if HAVE_CYTHON |
| 5 | SUBDIRS += cython | 5 | SUBDIRS += cython |
| 6 | endif | 6 | endif |
| 7 | if BUILD_FUZZERS | ||
| 8 | SUBDIRS += fuzz | ||
| 9 | endif | ||
| 7 | 10 | ||
| 8 | docs/html: $(top_builddir)/doxygen.cfg $(top_srcdir)/include/plist/*.h | 11 | docs/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]) |
| 157 | esac | 157 | esac |
| 158 | 158 | ||
| 159 | AC_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]) | ||
| 164 | if 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]) | ||
| 226 | fi | ||
| 227 | AM_CONDITIONAL([BUILD_FUZZERS],[test "x$build_fuzzers" = "xtrue"]) | ||
| 228 | |||
| 159 | m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) | 229 | m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) |
| 160 | 230 | ||
| 161 | AC_OUTPUT([ | 231 | AC_OUTPUT([ |
| @@ -168,6 +238,7 @@ include/Makefile | |||
| 168 | tools/Makefile | 238 | tools/Makefile |
| 169 | cython/Makefile | 239 | cython/Makefile |
| 170 | test/Makefile | 240 | test/Makefile |
| 241 | fuzz/Makefile | ||
| 171 | doxygen.cfg | 242 | doxygen.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 @@ | |||
| 1 | if BUILD_FUZZERS | ||
| 2 | |||
| 3 | libFuzzer.a: Fuzzer/build.sh | ||
| 4 | @echo "Building $@" | ||
| 5 | @./Fuzzer/build.sh | ||
| 6 | |||
| 7 | Fuzzer/build.sh: LIBFUZZER_SRC | ||
| 8 | |||
| 9 | LIBFUZZER_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 | |||
| 20 | CLEANFILES = libFuzzer.a | ||
| 21 | |||
| 22 | noinst_PROGRAMS = xplist_fuzzer bplist_fuzzer | ||
| 23 | |||
| 24 | xplist_fuzzer_SOURCES = xplist_fuzzer.cc | ||
| 25 | xplist_fuzzer_LDFLAGS = -static | ||
| 26 | xplist_fuzzer_LDADD = $(top_builddir)/src/libplist.la libFuzzer.a | ||
| 27 | |||
| 28 | bplist_fuzzer_SOURCES = bplist_fuzzer.cc | ||
| 29 | bplist_fuzzer_LDFLAGS = -static | ||
| 30 | bplist_fuzzer_LDADD = $(top_builddir)/src/libplist.la libFuzzer.a | ||
| 31 | |||
| 32 | TESTS = fuzzers.test | ||
| 33 | |||
| 34 | EXTRA_DIST = bplist.dict xplist.dict init-fuzzers.sh test-fuzzers.sh fuzzers.test | ||
| 35 | |||
| 36 | endif | ||
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 | |||
| 3 | set -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 | |||
| 3 | CURDIR=`pwd` | ||
| 4 | FUZZDIR=`dirname $0` | ||
| 5 | |||
| 6 | cd ${FUZZDIR} | ||
| 7 | |||
| 8 | if ! 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 | ||
| 12 | fi | ||
| 13 | |||
| 14 | mkdir -p xplist-input | ||
| 15 | cp ../test/data/*.plist xplist-input/ | ||
| 16 | ./xplist_fuzzer -merge=1 xplist-input crashes leaks -dict=xplist.dict | ||
| 17 | |||
| 18 | mkdir -p bplist-input | ||
| 19 | cp ../test/data/*.bplist bplist-input/ | ||
| 20 | ./bplist_fuzzer -merge=1 bplist-input crashes leaks -dict=bplist.dict | ||
| 21 | |||
| 22 | cd ${CURDIR} | ||
| 23 | exit 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 | |||
| 3 | CURDIR=`pwd` | ||
| 4 | FUZZDIR=`dirname $0` | ||
| 5 | |||
| 6 | cd ${FUZZDIR} | ||
| 7 | |||
| 8 | if ! 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 | ||
| 12 | fi | ||
| 13 | |||
| 14 | if ! 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 | ||
| 18 | fi | ||
| 19 | |||
| 20 | echo "### TESTING xplist_fuzzer ###" | ||
| 21 | if ! ./xplist_fuzzer xplist-input -dict=xplist.dict -runs=10000; then | ||
| 22 | cd ${CURDIR} | ||
| 23 | exit 1 | ||
| 24 | fi | ||
| 25 | |||
| 26 | echo "### TESTING bplist_fuzzer ###" | ||
| 27 | if ! ./bplist_fuzzer bplist-input -dict=bplist.dict -runs=10000; then | ||
| 28 | cd ${CURDIR} | ||
| 29 | exit 1 | ||
| 30 | fi | ||
| 31 | |||
| 32 | cd ${CURDIR} | ||
| 33 | exit 0 | ||
