binutils: add fuzz_nm preconditions (#6801)

This commit is contained in:
DavidKorczynski 2021-11-08 22:46:21 +00:00 committed by GitHub
parent cdde6fe9ec
commit 758a3c6946
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View File

@ -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/

View File

@ -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

View File

@ -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;