aboutsummaryrefslogtreecommitdiff
path: root/configure.ac
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2020-11-09 16:41:55 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2020-11-09 16:44:39 +0000
commit3eb1519bd784076f63fed6678b88f918317a2124 (patch)
treeb0ecce81cfe4e4612b2f8979933a7ea18a876846 /configure.ac
parent0dcb6e5eb4bad32ef5676c533ece81e988a1c03b (diff)
downloadrtmux-3eb1519bd784076f63fed6678b88f918317a2124.tar.gz
rtmux-3eb1519bd784076f63fed6678b88f918317a2124.tar.bz2
rtmux-3eb1519bd784076f63fed6678b88f918317a2124.zip
Scaffold for oss-fuzz, from Sergey Nizovtsev.
Diffstat (limited to 'configure.ac')
-rw-r--r--configure.ac47
1 files changed, 44 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac
index cf621835..97010df4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -21,6 +21,26 @@ SAVED_CFLAGS="$CFLAGS"
SAVED_CPPFLAGS="$CPPFLAGS"
SAVED_LDFLAGS="$LDFLAGS"
+# Is this oss-fuzz build?
+AC_ARG_ENABLE(
+ fuzzing,
+ AC_HELP_STRING(--enable-fuzzing, build fuzzers)
+)
+AC_ARG_VAR(
+ FUZZING_LIBS,
+ AC_HELP_STRING(libraries to link fuzzing targets with)
+)
+
+# Set up convenient fuzzing defaults before initializing compiler.
+if test "x$enable_fuzzing" = xyes; then
+ AC_DEFINE(NEED_FUZZING)
+ test "x$CC" == x && CC=clang
+ test "x$FUZZING_LIBS" == x && \
+ FUZZING_LIBS="-fsanitize=fuzzer"
+ test "x$SAVED_CFLAGS" == x && \
+ AM_CFLAGS="-g -fsanitize=fuzzer-no-link,address"
+fi
+
# Set up the compiler in two different ways and say yes we may want to install.
AC_PROG_CC
AM_PROG_CC_C_O
@@ -54,8 +74,11 @@ if test "x$enable_static" = xyes; then
LDFLAGS="$AM_LDFLAGS $SAVED_LDFLAGS"
fi
+# Do we need fuzzers?
+AM_CONDITIONAL(NEED_FUZZING, test "x$enable_fuzzing" = xyes)
+
# Is this gcc?
-AM_CONDITIONAL(IS_GCC, test "x$GCC" = xyes)
+AM_CONDITIONAL(IS_GCC, test "x$GCC" = xyes -a "x$enable_fuzzing" != xyes)
# Is this Sun CC?
AC_EGREP_CPP(
@@ -117,8 +140,6 @@ AC_REPLACE_FUNCS([ \
getline \
getprogname \
memmem \
- recallocarray \
- reallocarray \
setenv \
setproctitle \
strcasestr \
@@ -130,6 +151,26 @@ AC_REPLACE_FUNCS([ \
])
AC_FUNC_STRNLEN
+# Clang sanitizers wrap reallocarray even if it isn't available on the target
+# system. When compiled it always returns NULL and crashes the program. To
+# detect this we need a more complicated test.
+AC_MSG_CHECKING([for working reallocarray])
+AC_RUN_IFELSE([AC_LANG_PROGRAM(
+ [#include <stdlib.h>],
+ [return (reallocarray(NULL, 1, 1) == NULL);]
+ )],
+ AC_MSG_RESULT(yes),
+ [AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
+)
+AC_MSG_CHECKING([for working recallocarray])
+AC_RUN_IFELSE([AC_LANG_PROGRAM(
+ [#include <stdlib.h>],
+ [return (recallocarray(NULL, 1, 1, 1) == NULL);]
+ )],
+ AC_MSG_RESULT(yes),
+ [AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
+)
+
# Look for clock_gettime. Must come before event_init.
AC_SEARCH_LIBS(clock_gettime, rt)