Skip to content

Commit d505a1f

Browse files
logger: make sure to overwrite harness instead of appending (#878)
This is causing issues where we have multiple harnesses in a single *.fuzz_target Signed-off-by: David Korczynski <[email protected]>
1 parent 77784e5 commit d505a1f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

logger.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,25 @@ def process(self, msg, kwargs):
3737
kwargs['extra'] = {**(self.extra or {}), **(kwargs.get('extra') or {})}
3838
return msg, kwargs
3939

40-
def write_to_file(self, file_path: str, file_content: str) -> None:
40+
def write_to_file(self,
41+
file_path: str,
42+
file_content: str,
43+
mode: str = 'a') -> None:
4144
"""Writes the |file_content| into a local |file_path|."""
42-
with open(file_path, 'a') as file:
45+
with open(file_path, mode) as file:
4346
file.writelines(file_content)
4447

4548
def write_fuzz_target(self, result: Result) -> None:
4649
"""Writes fuzz target."""
4750
fuzz_target_path = os.path.join(result.work_dirs.fuzz_targets,
4851
f'{result.trial:02d}.fuzz_target')
49-
self.write_to_file(fuzz_target_path, result.fuzz_target_source)
52+
self.write_to_file(fuzz_target_path, result.fuzz_target_source, 'w')
5053

5154
def write_build_script(self, result: Result) -> None:
5255
"""Writes build script."""
5356
build_script_path = os.path.join(result.work_dirs.fuzz_targets,
5457
f'{result.trial:02d}.build_script')
55-
self.write_to_file(build_script_path, result.build_script_source)
58+
self.write_to_file(build_script_path, result.build_script_source, 'w')
5659

5760
def write_result(self, result_status_dir: str, result: TrialResult) -> None:
5861
"""Writes the final result into JSON for report generation."""

0 commit comments

Comments
 (0)