From: Ondřej Surý Date: Fri, 31 Jul 2020 13:20:56 +0000 (+0200) Subject: Re-enable the fuzzing tests X-Git-Tag: v9.17.4~19^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=23b1caabaeb1f8f74803b3dbf2248b6e6e841ba8;p=thirdparty%2Fbind9.git Re-enable the fuzzing tests The fuzzing tests were temporarily disabled when the build system has been converted to automake. This commit restores the functionality to run the fuzzing tests as part of the `make check`. When the afl or libfuzzer is enabled via ./configure, it uses a custom LOG_DRIVER (fuzz/). Currently only libfuzzer.sh has been implemented that runs each fuzz test for 5 seconds each. --- diff --git a/Makefile.am b/Makefile.am index 8b95fa378bd..88c72f144de 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ include $(top_srcdir)/Makefile.top -SUBDIRS = . libltdl lib doc bin +SUBDIRS = . libltdl lib doc bin fuzz BUILT_SOURCES = bind.keys.h CLEANFILES = bind.keys.h diff --git a/configure.ac b/configure.ac index 80c02b940a0..fdde51e2e3b 100644 --- a/configure.ac +++ b/configure.ac @@ -212,13 +212,18 @@ AS_CASE([$enable_fuzzing], AC_MSG_RESULT([using AFL]) AC_DEFINE([ENABLE_AFL], [1], [Define to enable American Fuzzy Lop test harness]) - CFLAGS="$CFLAGS -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1" - LIBS="$LIBS -lpthread"], + STD_CFLAGS="$STD_CFLAGS -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1" + FUZZ_LOG_COMPILER="afl.sh"], [libfuzzer],[ AC_MSG_RESULT([using libFuzzer]) - CFLAGS="$CFLAGS -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1 -fsanitize=fuzzer,address,undefined" - LDFLAGS="$LDFLAGS -fsanitize=fuzzer,address,undefined"], + STD_CFLAGS="$STD_CFLAGS -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1 -fsanitize=fuzzer-no-link,address,undefined" + LDFLAGS="$LDFLAGS -fsanitize=address,undefined" + FUZZ_LDFLAGS="-fsanitize=fuzzer,address,undefined" + FUZZ_LOG_COMPILER="libfuzzer.sh"], [*],[AC_MSG_ERROR([You need to explicitly select the fuzzer])]) +AM_CONDITIONAL([HAVE_FUZZ_LOG_COMPILER], [test -n "$FUZZ_LOG_COMPILER"]) +AC_SUBST([FUZZ_LOG_COMPILER]) +AC_SUBST([FUZZ_LDFLAGS]) AS_IF([test "$enable_fuzzing" = "afl"], [AC_MSG_CHECKING("for AFL enabled compiler") @@ -1672,6 +1677,10 @@ AC_CONFIG_FILES([bin/tests/system/start.sh], AC_CONFIG_FILES([bin/tests/system/stop.sh], [chmod +x bin/tests/system/stop.sh]) +# Fuzz Tests + +AC_CONFIG_FILES([fuzz/Makefile]) + # Misc AC_CONFIG_FILES([util/check-make-install]) diff --git a/fuzz/Makefile.am b/fuzz/Makefile.am new file mode 100644 index 00000000000..d3c858a606f --- /dev/null +++ b/fuzz/Makefile.am @@ -0,0 +1,39 @@ +include $(top_srcdir)/Makefile.top + +AM_CPPFLAGS += \ + $(LIBISC_CFLAGS) \ + $(LIBDNS_CFLAGS) \ + -DFUZZDIR=\"$(abs_srcdir)\" + +AM_LDFLAGS = \ + $(FUZZ_LDFLAGS) + +LDADD = \ + libfuzzmain.la \ + $(LIBISC_LIBS) \ + $(LIBDNS_LIBS) + +check_LTLIBRARIES = libfuzzmain.la +libfuzzmain_la_SOURCES = \ + main.c + +check_PROGRAMS = \ + dns_name_fromtext_target \ + dns_rdata_fromwire_text \ + isc_lex_getmastertoken \ + isc_lex_gettoken + +EXTRA_DIST = \ + dns_name_fromtext_target.in \ + dns_rdata_fromwire_text.in \ + isc_lex_getmastertoken.in \ + isc_lex_gettoken.in + +TESTS = $(check_PROGRAMS) + +if HAVE_FUZZ_LOG_COMPILER +LOG_COMPILER = $(srcdir)/$(FUZZ_LOG_COMPILER) +AM_LOG_FLAGS = $(srcdir) +endif HAVE_FUZZ_LOG_COMPILER + +unit-local: check diff --git a/fuzz/afl.sh b/fuzz/afl.sh new file mode 100755 index 00000000000..b97862af8a8 --- /dev/null +++ b/fuzz/afl.sh @@ -0,0 +1,14 @@ +#!/bin/sh +# +# Copyright (C) Internet Systems Consortium, Inc. ("ISC") +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# See the COPYRIGHT file distributed with this work for additional +# information regarding copyright ownership. + +echo "The AFL log compiler is not implemented yet." + +exit 1 diff --git a/fuzz/libfuzzer.sh b/fuzz/libfuzzer.sh new file mode 100755 index 00000000000..e925480e55c --- /dev/null +++ b/fuzz/libfuzzer.sh @@ -0,0 +1,12 @@ +#!/bin/sh -ex +# +# Copyright (C) Internet Systems Consortium, Inc. ("ISC") +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# See the COPYRIGHT file distributed with this work for additional +# information regarding copyright ownership. + +exec "${2}" "${1}/$(basename "${2}").in" -max_total_time=5 -print_pcs=1 -print_final_stats=1 -print_corpus_stats=1 -print_coverage=1 diff --git a/util/copyrights b/util/copyrights index 7b80b03a7fa..4bfaa43a9a7 100644 --- a/util/copyrights +++ b/util/copyrights @@ -1236,9 +1236,11 @@ ./docutil/patch-db2latex-duplicate-template-bug X 2007,2018,2019,2020 ./docutil/patch-db2latex-nested-param-bug X 2007,2018,2019,2020 ./docutil/patch-db2latex-xsltproc-title-bug X 2007,2018,2019,2020 +./fuzz/afl.sh SH 2020 ./fuzz/dns_name_fromtext_target.c C 2018,2019,2020 ./fuzz/dns_rdata_fromwire_text.c C 2019,2020 ./fuzz/fuzz.h C 2018,2019,2020 +./fuzz/libfuzzer.sh SH 2020 ./fuzz/main.c C 2018,2019,2020 ./lib/bind9/api X 2001,2006,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020 ./lib/bind9/check.c C 2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020