]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
build-system: add --enable-fuzzers
authorEvgeny Vereshchagin <evvers@ya.ru>
Wed, 14 Apr 2021 09:20:31 +0000 (09:20 +0000)
committerEvgeny Vereshchagin <evvers@ya.ru>
Mon, 26 Apr 2021 19:57:56 +0000 (19:57 +0000)
Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
configure.ac
src/tests/Makefile.am

index aa7f59a19dfff0514fb1e1ddb225fe919ff60e4d..094fe146b09974c402eee3b0057f471311d7229f 100644 (file)
@@ -62,6 +62,7 @@ if test "x$valid_compiler" = "xno"; then
 fi
 
 AC_PROG_GCC_TRADITIONAL
+AC_PROG_CXX
 AC_ENABLE_SHARED
 AC_ENABLE_STATIC
 # Check binaries
@@ -205,6 +206,13 @@ AC_ARG_ENABLE([no_undefined],
        [enable_no_undefined=$enableval], [enable_no_undefined=yes])
 AM_CONDITIONAL([ENABLE_NO_UNDEFINED], [test "x$enable_no_undefined" = "xyes"])
 
+AC_ARG_ENABLE([fuzzers],
+       [AS_HELP_STRING([--enable-fuzzers], [compile with fuzzers])],
+       [enable_fuzzers=$enableval], [enable_fuzzers=no])
+AM_CONDITIONAL([ENABLE_FUZZERS], [test "x$enable_fuzzers" = "xyes"])
+
+AM_CONDITIONAL([OSS_FUZZ], [test "x$LIB_FUZZING_ENGINE" != x])
+
 # Allow disabling rpath
 AC_ARG_ENABLE([rpath],
        [AS_HELP_STRING([--enable-rpath], [set rpath in executables [default=no]])],
@@ -476,6 +484,13 @@ else
        AC_MSG_RESULT([no])
 fi
 
+if test "x$enable_fuzzers" = "xyes" -a "x$LIB_FUZZING_ENGINE" = x; then
+       CC_CHECK_FLAGS_APPEND([AM_CFLAGS],[CFLAGS],[ \
+               -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION \
+               -fsanitize=fuzzer-no-link])
+       AC_SUBST(AM_CFLAGS)
+fi
+
 # Optional test binaries
 AC_ARG_ENABLE([tests],
        [AS_HELP_STRING([--enable-tests], [build test/example binaries [default=no]])],
@@ -1124,6 +1139,7 @@ Debugging:
  - Coverity: $enable_coverity_build
  - mutex debugging: $enable_mutex_debugging
  - tests: $enable_tests
+ - fuzzers: $enable_fuzzers
 
 Paths:
  - Logs in configpath: $enable_configpath_log
index 69e80d751f0075d96b68a9644ee1515a39e1a9a8..638d19607e0abc4446a57aba46f5170dda66d42b 100644 (file)
@@ -791,6 +791,27 @@ bin_SCRIPTS += lxc-test-lxc-attach \
 endif
 endif
 
+if ENABLE_FUZZERS
+LIB_FUZZING_ENGINE ?= -fsanitize=fuzzer
+
+# https://google.github.io/oss-fuzz/getting-started/new-project-guide/#Requirements
+nodist_EXTRA_fuzz_lxc_config_read_SOURCES = dummy.cxx
+fuzz_lxc_config_read_SOURCES = fuzz-lxc-config-read.c
+fuzz_lxc_config_read_CFLAGS = $(AM_CFLAGS)
+fuzz_lxc_config_read_CXXFLAGS = $(AM_CFLAGS)
+fuzz_lxc_config_read_LDFLAGS = $(AM_LDFLAGS) -static
+fuzz_lxc_config_read_LDADD = $(LDADD) $(LIB_FUZZING_ENGINE)
+
+nodist_EXTRA_fuzz_lxc_define_load_SOURCES = dummy.cxx
+fuzz_lxc_define_load_SOURCES = fuzz-lxc-define-load.c
+fuzz_lxc_define_load_CFLAGS = $(AM_CFLAGS)
+fuzz_lxc_define_load_CXXFLAGS = $(AM_CFLAGS)
+fuzz_lxc_define_load_LDFLAGS = $(AM_LDFLAGS) -static
+fuzz_lxc_define_load_LDADD = $(LDADD) $(LIB_FUZZING_ENGINE)
+
+bin_PROGRAMS += fuzz-lxc-config-read \
+               fuzz-lxc-define-load
+endif
 endif
 
 EXTRA_DIST = basic.c \