fuzz: Support build with -fsanitize=fuzzer instead of libFuzzer.a
authorTobias Brunner <tobias@strongswan.org>
Wed, 17 Jul 2019 09:16:19 +0000 (11:16 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 17 Jul 2019 09:44:27 +0000 (11:44 +0200)
Recent clang versions (6.0+) include libFuzzer and OSS-Fuzz switched to
that mode a while ago.

configure.ac
fuzz/Makefile.am

index 186202a..5dc1ae2 100644 (file)
@@ -63,7 +63,7 @@ ARG_WITH_SUBST([routing-table],      [220], [set routing table to use for IPsec
 ARG_WITH_SUBST([routing-table-prio], [220], [set priority for IPsec routing table])
 ARG_WITH_SUBST([ipsec-script],       [ipsec], [change the name of the ipsec script])
 ARG_WITH_SUBST([fips-mode],          [0], [set openssl FIPS mode: disabled(0), enabled(1), Suite B enabled(2)])
 ARG_WITH_SUBST([routing-table-prio], [220], [set priority for IPsec routing table])
 ARG_WITH_SUBST([ipsec-script],       [ipsec], [change the name of the ipsec script])
 ARG_WITH_SUBST([fips-mode],          [0], [set openssl FIPS mode: disabled(0), enabled(1), Suite B enabled(2)])
-ARG_WITH_SUBST([libfuzzer],          [], [path to libFuzzer.a])
+ARG_WITH_SUBST([libfuzzer],          [], [-fsanitize=fuzzer or path to libFuzzer.a, a local driver is used if not specified])
 ARG_WITH_SET([capabilities],         [no], [set capability dropping library. Currently supported values are "libcap" and "native"])
 ARG_WITH_SET([mpz_powm_sec],         [yes], [use the more side-channel resistant mpz_powm_sec in libgmp, if available])
 ARG_WITH_SET([dev-headers],          [no], [install strongSwan development headers to directory.])
 ARG_WITH_SET([capabilities],         [no], [set capability dropping library. Currently supported values are "libcap" and "native"])
 ARG_WITH_SET([mpz_powm_sec],         [yes], [use the more side-channel resistant mpz_powm_sec in libgmp, if available])
 ARG_WITH_SET([dev-headers],          [no], [install strongSwan development headers to directory.])
@@ -1294,18 +1294,26 @@ if test x$coverage = xtrue; then
 fi
 
 if test x$fuzzing = xtrue; then
 fi
 
 if test x$fuzzing = xtrue; then
-       if test x$libfuzzer = x; then
+       case "$libfuzzer" in
+       "")
                AC_MSG_NOTICE([fuzz targets enabled without libFuzzer, using local driver])
                CFLAGS="${CFLAGS} -fsanitize=address"
                libfuzzer="libFuzzerLocal.a"
                AC_MSG_NOTICE([fuzz targets enabled without libFuzzer, using local driver])
                CFLAGS="${CFLAGS} -fsanitize=address"
                libfuzzer="libFuzzerLocal.a"
-       else
+               ;;
+       "-fsanitize=fuzzer")
+               libfuzzer=""
+               FUZZING_CFLAGS="-fsanitize=fuzzer"
+               AC_SUBST(FUZZING_CFLAGS)
+               ;;
+       *)
                # required for libFuzzer
                FUZZING_LDFLAGS="-stdlib=libc++ -lstdc++"
                if test "$SANITIZER" = "coverage"; then
                        FUZZING_LDFLAGS="$FUZZING_LDFLAGS -lm"
                fi
                AC_SUBST(FUZZING_LDFLAGS)
                # required for libFuzzer
                FUZZING_LDFLAGS="-stdlib=libc++ -lstdc++"
                if test "$SANITIZER" = "coverage"; then
                        FUZZING_LDFLAGS="$FUZZING_LDFLAGS -lm"
                fi
                AC_SUBST(FUZZING_LDFLAGS)
-       fi
+               ;;
+       esac
 fi
 
 if test x$ruby_gems = xtrue; then
 fi
 
 if test x$ruby_gems = xtrue; then
index df228d3..de0a260 100644 (file)
@@ -1,4 +1,5 @@
 AM_CPPFLAGS = @CPPFLAGS@ \
 AM_CPPFLAGS = @CPPFLAGS@ \
+       @FUZZING_CFLAGS@ \
        -I$(top_srcdir)/src/libstrongswan \
        -I$(top_srcdir)/src/libimcv \
        -I$(top_srcdir)/src/libtncif \
        -I$(top_srcdir)/src/libstrongswan \
        -I$(top_srcdir)/src/libimcv \
        -I$(top_srcdir)/src/libtncif \