aboutsummaryrefslogtreecommitdiff
path: root/projects/envoy
diff options
context:
space:
mode:
authorhtuch <htuch@users.noreply.github.com>2018-11-02 10:41:32 -0400
committerjonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com>2018-11-02 07:41:32 -0700
commit991bf32f47a909c849a2207348e34859d9cf96b2 (patch)
treefba1cd3a91069fed62c528c99f33d2712569cfc9 /projects/envoy
parent96fce46d4adc6fbcfafc567f20513a42a56e7e57 (diff)
downloadoss-fuzz-991bf32f47a909c849a2207348e34859d9cf96b2.tar.gz
envoy: use Bazel to build corpora. (#1917)
* envoy: use Bazel to build corpora. Rather than scraping this out of the source tree, build each corpus under Bazel. The advantage is that we can now support synthesized corpora, e.g. automated generation from unit tests. Signed-off-by: Harvey Tuch <htuch@google.com> * Review feedback. Signed-off-by: Harvey Tuch <htuch@google.com>
Diffstat (limited to 'projects/envoy')
-rw-r--r--projects/envoy/Dockerfile2
-rwxr-xr-xprojects/envoy/build.sh26
-rw-r--r--projects/envoy/find_corpus.py23
3 files changed, 21 insertions, 30 deletions
diff --git a/projects/envoy/Dockerfile b/projects/envoy/Dockerfile
index dfe3c0ae2..095786dc0 100644
--- a/projects/envoy/Dockerfile
+++ b/projects/envoy/Dockerfile
@@ -37,4 +37,4 @@ RUN apt-get update && apt-get install -y bazel
RUN git clone https://github.com/envoyproxy/envoy.git
WORKDIR $SRC/envoy/
-COPY find_corpus.py build.sh $SRC/
+COPY build.sh $SRC/
diff --git a/projects/envoy/build.sh b/projects/envoy/build.sh
index 4dd9e2c68..88a21e8ed 100755
--- a/projects/envoy/build.sh
+++ b/projects/envoy/build.sh
@@ -45,6 +45,7 @@ done
)"
declare BAZEL_BUILD_TARGETS=""
+declare BAZEL_CORPUS_TARGETS=""
declare FILTERED_FUZZER_TARGETS=""
for t in ${FUZZER_TARGETS}
do
@@ -54,6 +55,7 @@ do
then
FILTERED_FUZZER_TARGETS+="$t "
BAZEL_BUILD_TARGETS+="${BAZEL_PATH}_driverless "
+ BAZEL_CORPUS_TARGETS+="${BAZEL_PATH}_corpus_tar "
fi
done
@@ -67,7 +69,7 @@ bazel build --verbose_failures --dynamic_mode=off --spawn_strategy=standalone \
--build_tag_filters=-no_asan \
${EXTRA_BAZEL_FLAGS} \
--linkopt="-lFuzzingEngine" \
- ${BAZEL_BUILD_TARGETS[*]}
+ ${BAZEL_BUILD_TARGETS[*]} ${BAZEL_CORPUS_TARGETS[*]}
# Profiling with coverage requires that we resolve+copy all Bazel symlinks and
# also remap everything under proc/self/cwd to correspond to Bazel build paths.
@@ -100,18 +102,30 @@ then
# /root/.cache "${OUT}"
fi
-# Copy out test driverless binaries from bazel-bin/ and zip up related test
-# corpuses.
+# Copy out test driverless binaries from bazel-bin/.
for t in ${FILTERED_FUZZER_TARGETS}
do
- TARGET_CORPUS=$(python "${SRC}"/find_corpus.py "$t")
TARGET_BASE="$(expr "$t" : '.*/\(.*\)_fuzz_test')"
TARGET_DRIVERLESS=bazel-bin/"${t}"_driverless
- echo "Copying fuzzer $t and corpus"
+ echo "Copying fuzzer $t"
cp "${TARGET_DRIVERLESS}" "${OUT}"/"${TARGET_BASE}"_fuzz_test
+done
+
+# Zip up related test corpuses.
+# TODO(htuch): just use the .tar directly when
+# https://github.com/google/oss-fuzz/issues/1918 is fixed.
+CORPUS_UNTAR_PATH="${PWD}"/_tmp_corpus
+for t in ${FILTERED_FUZZER_TARGETS}
+do
+ echo "Extracting and zipping fuzzer $t corpus"
+ rm -rf "${CORPUS_UNTAR_PATH}"
+ mkdir -p "${CORPUS_UNTAR_PATH}"
+ tar -C "${CORPUS_UNTAR_PATH}" -xvf bazel-bin/"${t}"_corpus_tar.tar
+ TARGET_BASE="$(expr "$t" : '.*/\(.*\)_fuzz_test')"
zip "${OUT}/${TARGET_BASE}"_fuzz_test_seed_corpus.zip \
- "$(dirname "${t}")"/"${TARGET_CORPUS}"/*
+ "${CORPUS_UNTAR_PATH}"/*
done
+rm -rf "${CORPUS_UNTAR_PATH}"
# Copy dictionaries and options files to $OUT/
for d in $FUZZER_DICTIONARIES; do
diff --git a/projects/envoy/find_corpus.py b/projects/envoy/find_corpus.py
deleted file mode 100644
index 712822ea1..000000000
--- a/projects/envoy/find_corpus.py
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/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]