]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
build: better integration of fuzz-decode in build process
authorVincent Bernat <vincent@bernat.ch>
Thu, 29 Dec 2022 22:25:05 +0000 (23:25 +0100)
committerVincent Bernat <vincent@bernat.ch>
Thu, 29 Dec 2022 22:25:05 +0000 (23:25 +0100)
I need it to reproduce crashs. Get rid of `build.sh` which does not work
with OOT compilation. Move the needed bits inside README. Simplify some
of the flags used.

README.md
configure.ac
src/client/Makefile.am
tests/Makefile.am
tests/decode.c
tests/fuzzer/build.sh [deleted file]

index 375874519a98d13dc3ac9e102a7b936c8ce98e60..8863d3618f164fb09857efa85ec40bdc41e8c832 100644 (file)
--- a/README.md
+++ b/README.md
@@ -360,10 +360,12 @@ To enable code coverage, use:
 
 ### With libfuzzer
 
-```
-./tests/fuzzer/build.sh ASan
-./tests/fuzzer/build.sh run
-```
+Build with `--enable-fuzzer` and `--enable-sanitizers`, then run `./fuzz-decode fuzzer/corpus
+fuzzer/seed-corpus` in `tests` folder. For example:
+
+- using address sanitizer: `./configure --enable-fuzzer --enable-sanitizers=address CFLAGS="-O1 -fsanitize-address-use-after-scope" CC=clang`
+- using undefined-behaviour sanitizer: `./configure --enable-fuzzer --enable-sanitizers=array-bounds,bool,builtin,enum,float-divide-by-zero,function,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unsigned-integer-overflow,unreachable,vla-bound,vptr CFLAGS="-O1 -fno-sanitize-recover=array-bounds,bool,builtin,enum,float-divide-by-zero,function,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound,vptr" CC=clang`
+- using memory sanitizer : `./configure --enable-fuzzer --enable-sanitizers=memory CFLAGS="-O1 -fsanitize-memory-track-origins" CC=clang`
 
 ### With AFL
 
index 4025244ba3271cb630bb8771b8efe42ede98386f..65e828aa848a99f952de92fc42342d4974287458 100644 (file)
@@ -147,7 +147,7 @@ elif test x"$hardening" != x"no"; then
 fi
   ])
 
-#Fuzzer
+# Fuzzer
 AC_ARG_ENABLE([fuzzer],
   AS_HELP_STRING([--enable-fuzzer],
     [Enable fuzzing @<:@default=no@:>@]),
@@ -158,7 +158,7 @@ case "$enableval" in
     *) fuzzer="$enableval" ;;
 esac
 if test x"$fuzzer" != x; then
-  AC_SUBST([FUZZENGINE], ["$fuzzer"])
+  AC_SUBST([FUZZ_DECODE_ENGINE], ["$fuzzer"])
 fi
   ])
 
@@ -420,7 +420,7 @@ AC_SUBST([LLDP_CFLAGS])
 AC_SUBST([LLDP_CPPFLAGS])
 AC_SUBST([LLDP_LDFLAGS])
 AC_SUBST([LLDP_BIN_LDFLAGS])
-AM_CONDITIONAL([BUILD_FUZZER], [test x"$fuzzer" != x])
+AM_CONDITIONAL([ENABLE_FUZZ_DECODE], [test x"$fuzzer" != x])
 AM_CONDITIONAL([HAVE_CHECK], [test x"$have_check" = x"yes"])
 AM_CONDITIONAL([USE_SNMP], [test x"$with_snmp" = x"yes"])
 AM_CONDITIONAL([USE_XML], [test x"$with_xml" = x"yes"])
index 23a3225c0d8914cc68bd68d7dd0fe65441b72e3b..89fb7161b261a63315e6da228fdfa0f6d83beb21 100644 (file)
@@ -23,7 +23,6 @@ lldpcli_LDADD    = \
        $(top_builddir)/src/libcommon-daemon-client.la \
        $(top_builddir)/src/lib/liblldpctl.la \
        @READLINE_LIBS@
-lldpcli_CFLAGS   = $(AM_CFLAGS)
 lldpcli_LDFLAGS  = $(AM_LDFLAGS) $(LLDP_BIN_LDFLAGS)
 
 if USE_XML
index b1e92f18555f9a3b2e3dfcf1ec883e89d862d4da..c3c0295bddda0a920351cfaf9f22a070e5e2643c 100644 (file)
@@ -3,12 +3,19 @@ AM_CPPFLAGS = $(LLDP_CPPFLAGS)
 AM_LDFLAGS = $(LLDP_LDFLAGS) $(LLDP_BIN_LDFLAGS)
 
 check_PROGRAMS = decode
-
 decode_SOURCES = decode.c \
        $(top_srcdir)/src/daemon/lldpd.h \
        pcap-hdr.h
 
-LDADD = $(top_builddir)/src/daemon/liblldpd.la @check_LIBS@ @libevent_LDFLAGS@
+if ENABLE_FUZZ_DECODE
+noinst_PROGRAMS = fuzz-decode
+fuzz_decode_CFLAGS = $(AM_CFLAGS) -DFUZZ_DECODE
+fuzz_decode_LDADD = $(FUZZ_DECODE_ENGINE) $(LDADD)
+fuzz_decode_SOURCES = decode.c \
+       $(top_srcdir)/src/daemon/lldpd.h
+endif
+
+LDADD = $(top_builddir)/src/daemon/liblldpd.la @libevent_LDFLAGS@
 if ENABLE_SYSTEMTAP
 LDADD += $(top_builddir)/src/daemon/probes.o
 endif
@@ -63,11 +70,4 @@ check_PROGRAMS += $(TESTS)
 
 endif
 
-if BUILD_FUZZER
-noinst_PROGRAMS = fuzz-decode
-fuzz_decode_CFLAGS = -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fPIE
-fuzz_decode_SOURCES = decode.c $(top_srcdir)/src/daemon/lldpd.h
-fuzz_decode_LDADD = $(LDADD) $(FUZZENGINE)
-endif
-
 MOSTLYCLEANFILES = *.pcap
index 85e5a070d8ac25d41f7e95357706a6b486123619..22b0aa053da8d47eaced1f5f436e6fac9194e62f 100644 (file)
 
 #define BUFSIZE 2000
 
-static void
-usage(void)
-{
-       fprintf(stderr, "Usage:   %s PCAP\n", "decode");
-       fprintf(stderr, "Version: %s\n", PACKAGE_STRING);
-
-       fprintf(stderr, "\n");
-
-       fprintf(stderr, "Decode content of PCAP files and display a summary\n");
-       fprintf(stderr, "on standard output. Only the first packet is decoded.\n");
-       exit(1);
-}
-
 char *
 tohex(char *str, size_t len)
 {
@@ -103,7 +90,7 @@ decode(char *frame, int size, struct lldpd_hardware *hardware,
        return decoded;
 }
 
-#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+#ifdef FUZZ_DECODE
 
 #  define kMinInputLength 30
 #  define kMaxInputLength 1500
@@ -128,6 +115,19 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
 
 #else
 
+static void
+usage(void)
+{
+       fprintf(stderr, "Usage:   %s PCAP\n", "decode");
+       fprintf(stderr, "Version: %s\n", PACKAGE_STRING);
+
+       fprintf(stderr, "\n");
+
+       fprintf(stderr, "Decode content of PCAP files and display a summary\n");
+       fprintf(stderr, "on standard output. Only the first packet is decoded.\n");
+       exit(1);
+}
+
 int
 main(int argc, char **argv)
 {
diff --git a/tests/fuzzer/build.sh b/tests/fuzzer/build.sh
deleted file mode 100755 (executable)
index 0011142..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/bin/bash -eu
-
-build() {
-   export CFLAGS="$1"
-
-   ./autogen.sh
-   ./configure CC="${CC:-clang}" CFLAGS="$CFLAGS" LDFLAGS="$CFLAGS" \
-      --enable-fuzzer=yes --disable-shared --disable-hardening --enable-pie
-
-   make -j$(nproc)
-   mkdir -p tests/fuzzer/corpus
-}
-
-run() {
-   cd tests
-   ./fuzz-decode fuzzer/corpus fuzzer/seed-corpus
-}
-
-help() {
-   echo "use: ./$0 ASan | UBSan | MSan | Run"
-}
-
-case $1 in
-   ASan) build "-O1 -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address -fsanitize-address-use-after-scope -fsanitize=fuzzer-no-link" ;;
-   UBSan) build "-O1 -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=array-bounds,bool,builtin,enum,float-divide-by-zero,function,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unsigned-integer-overflow,unreachable,vla-bound,vptr -fno-sanitize-recover=array-bounds,bool,builtin,enum,float-divide-by-zero,function,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound,vptr -fsanitize=fuzzer-no-link" ;;
-   MSan) build "-O1 -fno-omit-frame-pointer -gline-tables-only -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=memory -fsanitize-memory-track-origins -fsanitize=fuzzer-no-link" ;;
-   run) run ${2:-} ;;
-   *) help ;;
-esac