Skip to content

Commit

Permalink
centipede: create workdir in prepare instead of the constructor (#4674
Browse files Browse the repository at this point in the history
)

It turns out that the same class can be used for different fuzzing
rounds, and the parent directory of the temp dir is being cleared in
between each round. For that reason, we need to re-create a workdir in
`prepare`.
  • Loading branch information
paulsemel authored Feb 7, 2025
1 parent ca14f3a commit 77ea427
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/clusterfuzz/_internal/bot/fuzzers/centipede/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,6 @@ def _parse_centipede_logs(log_lines: List[str]) -> Dict[str, int]:
class Engine(engine.Engine):
"""Centipede engine implementation."""

def __init__(self):
super().__init__()
self.workdir = self._create_temp_dir('workdir')

@property
def name(self):
return 'centipede'
Expand Down Expand Up @@ -202,7 +198,8 @@ def prepare(self, corpus_dir, target_path, build_dir):
# 1. Centipede-readable corpus file;
# 2. Centipede-readable feature file;
# 3. Crash reproducing inputs.
arguments[constants.WORKDIR_FLAGNAME] = str(self.workdir)
workdir = self._create_temp_dir('workdir')
arguments[constants.WORKDIR_FLAGNAME] = str(workdir)

# Directory corpus_dir saves the corpus files required by ClusterFuzz.
arguments[constants.CORPUS_DIR_FLAGNAME] = corpus_dir
Expand Down Expand Up @@ -301,7 +298,12 @@ def fuzz(self, target_path, options, reproducers_dir, max_time): # pylint: disa
int(fuzz_result.time_executed)))

stats_filename = f'fuzzing-stats-{os.path.basename(target_path)}.000000.csv'
stats_file = os.path.join(self.workdir, stats_filename)
args = fuzzer_options.FuzzerArguments.from_list(options.arguments)
assert args is not None
assert constants.WORKDIR_FLAGNAME in args

workdir = args[constants.WORKDIR_FLAGNAME]
stats_file = os.path.join(workdir, stats_filename)
stats = _parse_centipede_stats(stats_file)
if not stats:
stats = {}
Expand Down Expand Up @@ -505,9 +507,10 @@ def minimize_testcase(self, target_path, arguments, input_path, output_path,
TimeoutError: If the testcase minimization exceeds max_time.
"""
runner = _get_runner(target_path)
workdir = self._create_temp_dir('workdir')
args = [
f'--binary={target_path}',
f'--workdir={self.workdir}',
f'--workdir={workdir}',
f'--minimize_crash={input_path}',
f'--num_runs={constants.NUM_RUNS_PER_MINIMIZATION}',
'--seed=1',
Expand All @@ -517,7 +520,7 @@ def minimize_testcase(self, target_path, arguments, input_path, output_path,
logs.warning(
'Testcase minimization timed out.', fuzzer_output=result.output)
raise TimeoutError('Minimization timed out.')
minimum_testcase = self._get_smallest_crasher(self.workdir)
minimum_testcase = self._get_smallest_crasher(workdir)
if minimum_testcase:
shutil.copyfile(minimum_testcase, output_path)
else:
Expand Down

0 comments on commit 77ea427

Please sign in to comment.