summaryrefslogtreecommitdiff
path: root/lib/fuzzer/scripts
diff options
context:
space:
mode:
authorMax Moroz <mmoroz@chromium.org>2019-04-04 21:20:36 +0000
committerMax Moroz <mmoroz@chromium.org>2019-04-04 21:20:36 +0000
commitf547015c30e5fad2347308c5c82346f2894c924f (patch)
tree357caba43d5c734d64537f9bec296a5f830dc06f /lib/fuzzer/scripts
parent3c3f14f22e369d9af39e2735ac93ecb2004bd2b6 (diff)
downloadcompiler-rt-f547015c30e5fad2347308c5c82346f2894c924f.tar.gz
[libFuzzer] Make DataFlow scripts Python3 compatible.
Summary: Python2 will hit end of life soon: https://pythonclock.org/ This change also makes the integration with OSS-Fuzz a bit simpler: https://github.com/google/oss-fuzz/issues/1632 Reviewers: morehouse, kcc Reviewed By: morehouse Subscribers: delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D60282 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@357726 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/fuzzer/scripts')
-rwxr-xr-xlib/fuzzer/scripts/collect_data_flow.py12
-rwxr-xr-xlib/fuzzer/scripts/merge_data_flow.py2
2 files changed, 8 insertions, 6 deletions
diff --git a/lib/fuzzer/scripts/collect_data_flow.py b/lib/fuzzer/scripts/collect_data_flow.py
index 5be8ae6aa..e8b56a719 100755
--- a/lib/fuzzer/scripts/collect_data_flow.py
+++ b/lib/fuzzer/scripts/collect_data_flow.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
#===- lib/fuzzer/scripts/collect_data_flow.py ------------------------------===#
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -39,7 +39,9 @@ def collect_dataflow_for_corpus(self, exe, corpus_dir, output_dir):
for root, dirs, files in os.walk(corpus_dir):
for f in files:
path = os.path.join(root, f)
- sha1 = hashlib.sha1(open(path).read()).hexdigest()
+ with open(path, 'rb') as fh:
+ data = fh.read()
+ sha1 = hashlib.sha1(data).hexdigest()
output = os.path.join(output_dir, sha1)
subprocess.call([self, exe, path, output])
functions_txt = open(os.path.join(output_dir, "functions.txt"), "w")
@@ -55,11 +57,11 @@ def main(argv):
q = [[0, size]]
tmpdir = tempfile.mkdtemp(prefix="libfuzzer-tmp-")
atexit.register(cleanup, tmpdir)
- print "tmpdir: ", tmpdir
+ print("tmpdir: ", tmpdir)
outputs = []
while len(q):
r = q.pop()
- print "******* Trying: ", r
+ print("******* Trying: ", r)
tmpfile = os.path.join(tmpdir, str(r[0]) + "-" + str(r[1]))
ret = subprocess.call([exe, str(r[0]), str(r[1]), inp, tmpfile])
if ret and r[1] - r[0] >= 2:
@@ -67,7 +69,7 @@ def main(argv):
q.append([(r[1] + r[0]) / 2, r[1]])
else:
outputs.append(tmpfile)
- print "******* Success: ", r
+ print("******* Success: ", r)
f = sys.stdout
if len(argv) >= 4:
f = open(argv[3], "w")
diff --git a/lib/fuzzer/scripts/merge_data_flow.py b/lib/fuzzer/scripts/merge_data_flow.py
index 1d2991d54..167d01f7c 100755
--- a/lib/fuzzer/scripts/merge_data_flow.py
+++ b/lib/fuzzer/scripts/merge_data_flow.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
#===- lib/fuzzer/scripts/merge_data_flow.py ------------------------------===#
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.