From cd8e557241d6da2583019959579dbb53e0a3c5af Mon Sep 17 00:00:00 2001 From: Anirudh Date: Thu, 19 Jul 2018 02:27:18 +0530 Subject: envoy: modified identification of corpus path (#1607) --- projects/envoy/Dockerfile | 2 +- projects/envoy/build.sh | 3 ++- projects/envoy/find_corpus.py | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 projects/envoy/find_corpus.py (limited to 'projects') diff --git a/projects/envoy/Dockerfile b/projects/envoy/Dockerfile index 8f5526ce..c260f229 100644 --- a/projects/envoy/Dockerfile +++ b/projects/envoy/Dockerfile @@ -36,4 +36,4 @@ RUN apt-get update && apt-get install -y bazel RUN git clone https://github.com/envoyproxy/envoy.git WORKDIR /src/envoy/ -COPY build.sh $SRC/ +COPY find_corpus.py build.sh $SRC/ diff --git a/projects/envoy/build.sh b/projects/envoy/build.sh index 3162d051..03253789 100755 --- a/projects/envoy/build.sh +++ b/projects/envoy/build.sh @@ -61,10 +61,11 @@ bazel build --verbose_failures --dynamic_mode=off --spawn_strategy=standalone \ # Copy out test binaries from bazel-bin/ and zip up related test corpuses. for t in ${FUZZER_TARGETS} do + TARGET_CORPUS=$(python "${SRC}"/find_corpus.py "$t") TARGET_BASE="$(expr "$t" : '.*/\(.*\)_fuzz_test')" cp bazel-bin/"${t}"_driverless "${OUT}"/"${TARGET_BASE}"_fuzz_test zip "${OUT}/${TARGET_BASE}"_fuzz_test_seed_corpus.zip \ - "$(dirname "${t}")"/"${TARGET_BASE}"_corpus/* + "$(dirname "${t}")"/"${TARGET_CORPUS}"/* done # Copy dictionaries and options files to $OUT/ diff --git a/projects/envoy/find_corpus.py b/projects/envoy/find_corpus.py new file mode 100644 index 00000000..712822ea --- /dev/null +++ b/projects/envoy/find_corpus.py @@ -0,0 +1,23 @@ +#!/usr/bin/python + +import os +import sys +import re + +fuzzer_target = sys.argv[1] +directory, fuzzer_target_name = os.path.dirname(fuzzer_target), os.path.basename(fuzzer_target) +path = os.path.join('..', 'envoy', directory, 'BUILD') + +with open(path, 'r') as f: + searchlines = f.readlines() + for i, line in enumerate(searchlines): + if fuzzer_target_name in line: + for l in searchlines[i:]: + if 'corpus =' in l: + corpus_path = l + break +try: + corpus_path +except NameError: + raise Exception("No corpus path for the given fuzz target") +print re.findall(r'"([^"]*)"', corpus_path)[0] -- cgit v1.2.3