aboutsummaryrefslogtreecommitdiffhomepage
path: root/infra/cifuzz/fuzz_target.py
diff options
context:
space:
mode:
Diffstat (limited to 'infra/cifuzz/fuzz_target.py')
-rw-r--r--infra/cifuzz/fuzz_target.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/infra/cifuzz/fuzz_target.py b/infra/cifuzz/fuzz_target.py
index 22c7b5f3..1aede43e 100644
--- a/infra/cifuzz/fuzz_target.py
+++ b/infra/cifuzz/fuzz_target.py
@@ -57,6 +57,9 @@ SANITIZER = 'address'
# The number of reproduce attempts for a crash.
REPRODUCE_ATTEMPTS = 10
+# Seconds on top of duration till a timeout error is raised.
+BUFFER_TIME = 10
+
class FuzzTarget:
"""A class to manage a single fuzz target.
@@ -82,7 +85,7 @@ class FuzzTarget:
project_name: The name of the relevant OSS-Fuzz project.
"""
self.target_name = os.path.basename(target_path)
- self.duration = duration
+ self.duration = int(duration)
self.target_path = target_path
self.out_dir = out_dir
self.project_name = project_name
@@ -109,7 +112,8 @@ class FuzzTarget:
'bash', '-c'
]
run_fuzzer_command = 'run_fuzzer {fuzz_target} {options}'.format(
- fuzz_target=self.target_name, options=LIBFUZZER_OPTIONS)
+ fuzz_target=self.target_name,
+ options=LIBFUZZER_OPTIONS + ' -max_total_time=' + str(self.duration))
# If corpus can be downloaded use it for fuzzing.
latest_corpus_path = self.download_latest_corpus()
@@ -121,13 +125,19 @@ class FuzzTarget:
process = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
-
try:
- _, err = process.communicate(timeout=self.duration)
+ _, err = process.communicate(timeout=self.duration + BUFFER_TIME)
except subprocess.TimeoutExpired:
- logging.info('Fuzzer %s, finished with timeout.', self.target_name)
+ logging.error('Fuzzer %s timed out, ending fuzzing.', self.target_name)
+ return None, None
+
+ # Libfuzzer timeout has been reached.
+ if not process.returncode:
+ logging.info('Fuzzer %s finished with no crashes discovered.',
+ self.target_name)
return None, None
+ # Crash has been discovered.
logging.info('Fuzzer %s, ended before timeout.', self.target_name)
err_str = err.decode('ascii')
test_case = self.get_test_case(err_str)