From 4d4111183be9bac4aede0be20f692a1ed5403bac Mon Sep 17 00:00:00 2001 From: DavidKorczynski Date: Sun, 7 Nov 2021 23:39:24 +0000 Subject: [PATCH] libdwarf: add seeds and cleanup fuzzers tt only used public headers (#6795) --- projects/libdwarf/Dockerfile | 1 + projects/libdwarf/build.sh | 14 ++++++++++++-- projects/libdwarf/fuzz_init_binary.c | 6 +++--- projects/libdwarf/fuzz_init_path.c | 6 +++--- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/projects/libdwarf/Dockerfile b/projects/libdwarf/Dockerfile index 065e058da..76d54d7b3 100644 --- a/projects/libdwarf/Dockerfile +++ b/projects/libdwarf/Dockerfile @@ -17,6 +17,7 @@ FROM gcr.io/oss-fuzz-base/base-builder RUN apt-get update && apt-get install -y make autoconf automake libtool RUN git clone --depth 1 https://github.com/davea42/libdwarf-code libdwarf +RUN git clone --depth=1 https://github.com/DavidKorczynski/binary-samples $SRC/binary-samples WORKDIR libdwarf COPY build.sh $SRC/ COPY fuzz*.c $SRC/ diff --git a/projects/libdwarf/build.sh b/projects/libdwarf/build.sh index 06ed9f67d..4c5a36995 100755 --- a/projects/libdwarf/build.sh +++ b/projects/libdwarf/build.sh @@ -15,14 +15,24 @@ # ################################################################################ -export CFLAGS="${CFLAGS} -g" -export CXXFLAGS="${CXXFLAGS} -g" +export CFLAGS="${CFLAGS} -g -Werror" +export CXXFLAGS="${CXXFLAGS} -g -Werror" mkdir build cd build cmake ../ make +# Build corpus for fuzzing +mkdir $SRC/corp +cp $SRC/binary-samples/elf* $SRC/corp +cp $SRC/binary-samples/Mach* $SRC/corp +cp $SRC/binary-samples/pe* $SRC/corp +cp $SRC/binary-samples/lib* $SRC/corp + +zip -r -j $OUT/fuzz_init_path_seed_corpus.zip $SRC/corp +cp $OUT/fuzz_init_path_seed_corpus.zip $OUT/fuzz_init_binary_seed_corpus.zip + for fuzzName in init_path init_binary; do $CC $CFLAGS $LIB_FUZZING_ENGINE -I../src/lib/libdwarf/ \ $SRC/fuzz_${fuzzName}.c -o $OUT/fuzz_${fuzzName} ./src/lib/libdwarf/libdwarf.a diff --git a/projects/libdwarf/fuzz_init_binary.c b/projects/libdwarf/fuzz_init_binary.c index 6c2b75673..0ab6491fd 100644 --- a/projects/libdwarf/fuzz_init_binary.c +++ b/projects/libdwarf/fuzz_init_binary.c @@ -18,11 +18,11 @@ limitations under the License. #include #include +/* + * Libdwarf library callers can only use these headers. + */ #include "dwarf.h" #include "libdwarf.h" -#include "libdwarf_private.h" -#include "dwarf_alloc.h" - /* * A fuzzer that simulates a small part of the simplereader.c example. diff --git a/projects/libdwarf/fuzz_init_path.c b/projects/libdwarf/fuzz_init_path.c index 382c1879a..2f72122d8 100644 --- a/projects/libdwarf/fuzz_init_path.c +++ b/projects/libdwarf/fuzz_init_path.c @@ -16,11 +16,11 @@ limitations under the License. #include #include +/* + * Libdwarf library callers can only use these headers. + */ #include "dwarf.h" #include "libdwarf.h" -#include "libdwarf_private.h" -#include "dwarf_alloc.h" - /* * A fuzzer that simulates a small part of the simplereader.c example.