diff --git a/configure.ac b/configure.ac index a87c33440afa5e96d34754217aba367a1c9c00f2..1b28be22a45629ea92f4b02e81f7477e9f00dbf4 100644 --- a/configure.ac +++ b/configure.ac @@ -512,8 +512,8 @@ gl_VISIBILITY() AX_CODE_COVERAGE AX_SANITIZER -AS_IF([test -n "$sanitize_CFLAGS"], [CFLAGS="$CFLAGS $sanitize_CFLAGS"]) -AM_CONDITIONAL([SANITIZE_FUZZER], [test "$with_sanitize_fuzzer" != "no"]) +AS_IF([test -n "$sanitizer_CFLAGS"], [CFLAGS="$CFLAGS $sanitizer_CFLAGS"]) +AM_CONDITIONAL([FUZZER], [test "$with_fuzzer" != "no"]) AM_CONDITIONAL([OSS_FUZZ], [test "$with_oss_fuzz" != "no"]) AS_IF([test "$enable_documentation" = "yes"],[ @@ -570,8 +570,8 @@ result_msg_base=" $PACKAGE $VERSION PKCS #11 support: ${enable_pkcs11} Ed25519 support: ${enable_ed25519} Code coverage: ${enable_code_coverage} - Sanitizer: ${with_sanitize} - LibFuzzer: ${with_sanitize_fuzzer} + Sanitizer: ${with_sanitizer} + LibFuzzer: ${with_fuzzer} OSS-Fuzz: ${with_oss_fuzz}" result_msg_esc=$(echo -n "$result_msg_base" | sed '$!s/$/\\n/' | tr -d '\n') diff --git a/m4/sanitizer.m4 b/m4/sanitizer.m4 index 86188eaa02ba9976c331670978ca39727d445846..276f032700617da094b7ab4c8708a51771f4af99 100644 --- a/m4/sanitizer.m4 +++ b/m4/sanitizer.m4 @@ -1,4 +1,4 @@ -# Copyright 2015-2017 CZ.NIC, z.s.p.o. +# Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License version 3, as published @@ -13,26 +13,27 @@ # with this program. If not, see <http://www.gnu.org/licenses/>. # -# Processes --with-sanitize and --with-oss-fuzz flags, checks +# Processes --with-sanitizer, --with-fuzzer, and --with-oss-fuzz flags, checks # if the options are supported by the compiler, and sets the following # variables accordingly: # -# - sanitize_enabled yes|no -# - sanitize_fuzzer_enabled yes|no -# - sanitize_CFLAGS -fsanitize=... +# - sanitizer_CFLAGS -fsanitize=... +# - fuzzer_CLAGS -fsanitize=... +# - fuzzer_LDLAGS -fsanitize=... # + AC_DEFUN([AX_SANITIZER], [ # Configure options - AC_ARG_WITH([sanitize], - [AS_HELP_STRING([--with-sanitize], [Compile with sanitizer [default=no]])], + AC_ARG_WITH([sanitizer], + [AS_HELP_STRING([--with-sanitizer], [Compile with sanitizer [default=no]])], [], - [with_sanitize=no] + [with_sanitizer=no] ) - AC_ARG_WITH([sanitize-fuzzer], - [AS_HELP_STRING([--with-sanitize-fuzzer], [Compile with sanitizer fuzzer (require clang >= 6.0) [default=no]])], + AC_ARG_WITH([fuzzer], + [AS_HELP_STRING([--with-fuzzer], [Compile with libfuzzer [default=no]])], [], - [with_sanitize_fuzzer=no] + [with_fuzzer=no] ) AC_ARG_WITH([oss-fuzz], [AS_HELP_STRING([--with-oss-fuzz], [Link for oss-fuzz environment [default=no]])], @@ -41,44 +42,40 @@ AC_DEFUN([AX_SANITIZER], [ ) # Using -fsanitize=fuzzer requires clang >= 6.0 - AS_IF([test "$with_sanitize_fuzzer" != "no"],[ + AS_IF([test "$with_fuzzer" != "no"],[ # Get clang version if empty AS_IF([test -z "$CC_CLANG_VERSION"],[AX_CC_CLANG]) AX_COMPARE_VERSION([$CC_CLANG_VERSION],ge,[6.0],[],[ - AC_MSG_ERROR([clang >= 6.0 required for sanitize fuzzer])])]) + AC_MSG_ERROR([clang >= 6.0 required for fuzzer])])]) # Default values - AS_IF([test "$with_sanitize" = "yes"], [ with_sanitize=address ]) - AS_IF([test "$with_sanitize_fuzzer" = "yes"], [ with_sanitize_fuzzer=fuzzer-no-link ]) + AS_IF([test "$with_sanitizer" = "yes"], [ with_sanitizer=address ]) + AS_IF([test "$with_fuzzer" = "yes"], [ with_fuzzer=fuzzer ]) # Construct output variables - sanitize_enabled=no - sanitize_fuzzer_enable=no - sanitize_CFLAGS= - AS_IF([test "$with_sanitize" != "no" -o "$with_sanitize_fuzzer" != "no"], [ - AS_IF([test "$with_sanitize" != "no"], [ - sanitize_enabled=yes - AS_IF([test "$with_sanitize_fuzzer" != "no"], [ # --with-sanitize and --with-sanitize-fuzzer - sanitize_CFLAGS="-fsanitize=${with_sanitize},${with_sanitize_fuzzer}" - sanitize_fuzzer_enabled=yes - ],[ # only --with-sanitize - sanitize_CFLAGS="-fsanitize=${with_sanitize}" - ]) - ],[ # only --with-sanitize-fuzzer - AS_IF([test "$with_sanitize_fuzzer" != "no"], [ - sanitize_CFLAGS="-fsanitize=${with_sanitize_fuzzer}" - sanitize_fuzzer_enabled=yes - ])]) + sanitizer_CFLAGS= + fuzzer_CFLAGS= + fuzzer_LDFLAGS= + AS_IF([test "$with_sanitizer" != "no"], [ + sanitizer_CFLAGS="-fsanitize=${with_sanitizer}" + ]) + AS_IF([test "$with_fuzzer" != "no"], [ + fuzzer_CFLAGS="-fsanitize=${with_fuzzer}" + fuzzer_LDFLAGS="-fsanitize=${with_fuzzer}" + ]) + AC_SUBST(fuzzer_CFLAGS) + AC_SUBST(fuzzer_LDFLAGS) - # Test compiler support + # Test compiler support + AS_IF([test -n "$sanitizer_CFLAGS" -o -n "$fuzzer_CFLAGS"], [ save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $sanitize_CFLAGS" - AC_MSG_CHECKING([whether compiler accepts '${sanitize_CFLAGS}' options]) + CFLAGS="$CFLAGS $sanitizer_CFLAGS $fuzzer_CFLAGS" + AC_MSG_CHECKING([whether compiler accepts '${sanitizer_CFLAGS} ${fuzzer_CFLAGS}']) AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [ AC_MSG_RESULT([yes]) ], [ AC_MSG_RESULT([no]) - AC_MSG_ERROR([Sanitizer options are not supported.]) + AC_MSG_ERROR([Options are not supported.]) ]) CFLAGS="$save_CFLAGS" ]) diff --git a/tests-fuzz/.gitignore b/tests-fuzz/.gitignore index ecc866b48a917c0bd456e9a2f9a3c811681a863c..dfccf41679a0aebd2570a354e7600327e8bd1068 100644 --- a/tests-fuzz/.gitignore +++ b/tests-fuzz/.gitignore @@ -4,7 +4,7 @@ /knotd_stdio /wrap/main.c -/*.trs -/*.log +*.trs +*.log /fuzz_packet /fuzz_zscanner diff --git a/tests-fuzz/Makefile.am b/tests-fuzz/Makefile.am index 72d49f35313ff976f52be127088e0e95a990f9ba..16611df03e5bdb9dfe5416654e15a47fcb83334b 100644 --- a/tests-fuzz/Makefile.am +++ b/tests-fuzz/Makefile.am @@ -13,26 +13,31 @@ FUZZERS = \ check_PROGRAMS = $(FUZZERS) -fuzz_packet_SOURCES = fuzz_packet.c -fuzz_packet_LDADD = $(top_builddir)/src/libknot.la +fuzz_packet_SOURCES = fuzz_packet.c +fuzz_packet_CPPFLAGS = $(AM_CPPFLAGS) +fuzz_packet_LDADD = $(top_builddir)/src/libknot.la -fuzz_zscanner_SOURCES = fuzz_zscanner.c -fuzz_zscanner_LDADD = $(top_builddir)/src/zscanner/libzscanner.la +fuzz_zscanner_SOURCES = fuzz_zscanner.c +fuzz_zscanner_CPPFLAGS = $(AM_CPPFLAGS) +fuzz_zscanner_LDADD = $(top_builddir)/src/zscanner/libzscanner.la if OSS_FUZZ # CFLAGS, LDFLAGS, etc. are defined by the oss-fuzz environment; just link # in the fuzzing engine -fuzz_packet_LDADD += ${LIB_FUZZING_ENGINE} -lc++ +fuzz_packet_LDADD += ${LIB_FUZZING_ENGINE} -lc++ fuzz_zscanner_LDADD += ${LIB_FUZZING_ENGINE} -lc++ else -if SANITIZE_FUZZER +if FUZZER -fuzz_packet_LDFLAGS = -fsanitize=fuzzer -fuzz_zscanner_LDFLAGS = -fsanitize=fuzzer +fuzz_packet_CPPFLAGS += ${fuzzer_CFLAGS} +fuzz_packet_LDFLAGS = ${fuzzer_LDFLAGS} + +fuzz_zscanner_CPPFLAGS += ${fuzzer_CFLAGS} +fuzz_zscanner_LDFLAGS = ${fuzzer_LDFLAGS} # Ensure that fuzzers execute successfully with a benign input @@ -41,12 +46,15 @@ EXTRA_DIST = check/check_fuzzers.test else -fuzz_packet_SOURCES += main.c -fuzz_zscanner_SOURCES += main.c -AM_CPPFLAGS += -DTEST_RUN +fuzz_packet_SOURCES += main.c +fuzz_packet_CPPFLAGS += -DTEST_RUN + +fuzz_zscanner_SOURCES += main.c +fuzz_zscanner_CPPFLAGS += -DTEST_RUN + TESTS = $(FUZZERS) -endif # if SANITIZE_FUZZER +endif # if FUZZER endif # if OSS_FUZZ