From 758a3c694650f50c468a7dfd0a13f828865a155f Mon Sep 17 00:00:00 2001 From: DavidKorczynski Date: Mon, 8 Nov 2021 22:46:21 +0000 Subject: [PATCH] binutils: add fuzz_nm preconditions (#6801) --- projects/binutils/Dockerfile | 1 + projects/binutils/build.sh | 4 ++++ projects/binutils/fuzz_nm.c | 5 ++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/projects/binutils/Dockerfile b/projects/binutils/Dockerfile index c5e663e69..9d82b6504 100644 --- a/projects/binutils/Dockerfile +++ b/projects/binutils/Dockerfile @@ -19,6 +19,7 @@ FROM gcr.io/oss-fuzz-base/base-builder RUN apt-get update && apt-get install -y make texinfo RUN apt-get install -y flex bison RUN git clone --recursive --depth 1 git://sourceware.org/git/binutils-gdb.git binutils-gdb +RUN git clone --depth=1 https://github.com/DavidKorczynski/binutils-preconditions binutils-preconditions WORKDIR $SRC COPY build.sh $SRC/ COPY fuzz_*.c $SRC/ diff --git a/projects/binutils/build.sh b/projects/binutils/build.sh index 0ca3bede9..f43286c72 100755 --- a/projects/binutils/build.sh +++ b/projects/binutils/build.sh @@ -40,6 +40,7 @@ cd ../ make clean make MAKEINFO=true && true + # Due to a bug in AFLPP that occurs *sometimes* we continue only if we have the # libraries that we need if ([ -f ./libctf/.libs/libctf.a ]); then @@ -76,6 +77,9 @@ if ([ -f ./libctf/.libs/libctf.a ]); then # The general strategy is to remove main functions such that the fuzzer (which has its own main) # can link against the code. + # Copy over precondition files + cp $SRC/binutils-preconditions/*.h . + # Patching # First do readelf. We do this by changing readelf.c to readelf.h - the others will be changed # to fuzz_readelf.h where readelf is their respective name. The reason it's different for readelf diff --git a/projects/binutils/fuzz_nm.c b/projects/binutils/fuzz_nm.c index e4edec38a..4defd6f46 100644 --- a/projects/binutils/fuzz_nm.c +++ b/projects/binutils/fuzz_nm.c @@ -16,6 +16,7 @@ limitations under the License. * the binutils fuzzers. */ #include "fuzz_nm.h" +#include "ada_nm.h" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size); int @@ -39,7 +40,9 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) // Main fuzz entrypoint in nm.c - display_file(filename); + if (fuzz_preconditions(filename) == 1) { + display_file(filename); + } unlink(filename); return 0;