Skip to content

Commit 81995e3

Browse files
[rearchitecture] Handle cases when target is not in zip. (#3973)
We should be able to handle cases when all fuzzers in a build are renamed.
1 parent 66f2069 commit 81995e3

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/clusterfuzz/_internal/bot/tasks/utasks/fuzz_task.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ class FuzzTaskError(Exception):
8383
"""Fuzz task exception."""
8484

8585

86+
class FuzzTargetNotFoundError(Exception):
87+
"""Fuzz target not in build."""
88+
89+
8690
class FuzzErrorCode:
8791
FUZZER_TIMEOUT = -1
8892
FUZZER_SETUP_FAILED = -2
@@ -1282,6 +1286,8 @@ def run_engine_fuzzer(engine_impl, target_name, sync_corpus_directory,
12821286

12831287
build_dir = environment.get_value('BUILD_DIR')
12841288
target_path = engine_common.find_fuzzer_path(build_dir, target_name)
1289+
if target_path is None:
1290+
raise FuzzTargetNotFoundError(f'{target_path} is not found.')
12851291
options = engine_impl.prepare(sync_corpus_directory, target_path, build_dir)
12861292

12871293
fuzz_test_timeout = environment.get_value('FUZZ_TEST_TIMEOUT')
@@ -1543,7 +1549,7 @@ def do_engine_fuzzing(self, engine_impl):
15431549
"""Run fuzzing engine."""
15441550
fuzz_target_name = environment.get_value('FUZZ_TARGET')
15451551
if not fuzz_target_name:
1546-
raise FuzzTaskError('No fuzz targets found.')
1552+
raise FuzzTaskError('No fuzz targets set.')
15471553
environment.set_value('FUZZER_NAME',
15481554
self.fuzz_target.fully_qualified_name())
15491555

@@ -1564,9 +1570,19 @@ def do_engine_fuzzing(self, engine_impl):
15641570
# Do the actual fuzzing.
15651571
for fuzzing_round in range(environment.get_value('MAX_TESTCASES', 1)):
15661572
logs.log(f'Fuzzing round {fuzzing_round}.')
1567-
result, current_fuzzer_metadata, fuzzing_strategies = run_engine_fuzzer(
1568-
engine_impl, self.fuzz_target.binary, sync_corpus_directory,
1569-
self.testcase_directory)
1573+
try:
1574+
result, current_fuzzer_metadata, fuzzing_strategies = run_engine_fuzzer(
1575+
engine_impl, self.fuzz_target.binary, sync_corpus_directory,
1576+
self.testcase_directory)
1577+
except FuzzTargetNotFoundError:
1578+
# Ocassionally fuzz targets are deleted. This is pretty rare. Since
1579+
# ClusterFuzz did nothing wrong, don't bubble up an exception, consider
1580+
# it as we fuzzed and nothing happened so that new targets can be
1581+
# recorded and hopefully fuzzed instead. The old targets will eventually
1582+
# be garbage collected. Log this as an error to keep an eye on it.
1583+
logs.log_error(f'{self.fuzz_target.binary} is not in the build.')
1584+
return [], {}
1585+
15701586
fuzzer_metadata.update(current_fuzzer_metadata)
15711587

15721588
# Prepare stats.

0 commit comments

Comments
 (0)