]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Re-enable the fuzzing tests
authorOndřej Surý <ondrej@sury.org>
Fri, 31 Jul 2020 13:20:56 +0000 (15:20 +0200)
committerOndřej Surý <ondrej@sury.org>
Fri, 31 Jul 2020 15:28:35 +0000 (17:28 +0200)
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/<fuzzer.sh>).

Currently only libfuzzer.sh has been implemented that runs each fuzz
test for 5 seconds each.

Makefile.am
configure.ac
fuzz/Makefile.am [new file with mode: 0644]
fuzz/afl.sh [new file with mode: 0755]
fuzz/libfuzzer.sh [new file with mode: 0755]
util/copyrights

index 8b95fa378bddff636125c6605362a81403214e7c..88c72f144de2fa9b2801600622b88b8f3f73cfa5 100644 (file)
@@ -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
index 80c02b940a0e35aa2721b7a7c6031afa465a1ca9..fdde51e2e3b277c79f431c0fea4bfdd051aa1f37 100644 (file)
@@ -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 (file)
index 0000000..d3c858a
--- /dev/null
@@ -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 (executable)
index 0000000..b97862a
--- /dev/null
@@ -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 (executable)
index 0000000..e925480
--- /dev/null
@@ -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
index 7b80b03a7faab81bd1c69f4b9221f176f68d9ae1..4bfaa43a9a7b8cb2eb9b92fd2865ed1db7954942 100644 (file)
 ./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