Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

envoy: modified identification of corpus path #1607

Merged
merged 4 commits into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion projects/envoy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
3 changes: 2 additions & 1 deletion projects/envoy/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
CORPUS_TARGET=$(python "${SRC}"/find_corpus.py "$t")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TARGET_CORPUS sounds better for name.

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}")"/"${CORPUS_TARGET}"/*
done

# Copy dictionaries and options files to $OUT/
Expand Down
23 changes: 23 additions & 0 deletions projects/envoy/find_corpus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/python

import os
import sys
import re

fuzzer_target = sys.argv[1].split('/')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use "/" quote style to be consistent with elsewhere in this file.

directory_segments, fuzz_test = fuzzer_target[:-1], fuzzer_target[-1]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use pythonic functions :) os.path.dirname and os.path.basename

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/fuzz_test/fuzz_target_name or fuzzer_target_name

directory = '/'.join(directory_segments)
path = '../envoy/' + directory + '/BUILD'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use os.path.join('..', 'envoy', ......)

corpus_path = ""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to use None


with open(path, 'r') as f:
searchlines = f.readlines()
for i, line in enumerate(searchlines):
if fuzz_test in line:
for l in searchlines[i:]:
if 'corpus =' in l:
corpus_path = l
break
if not corpus_path:
raise Exception("No corpus path for the given fuzz target")
print re.findall(r'"([^"]*)"', corpus_path)[0]