Skip to content

Get and log the source code of the fuzz target and build script. #1065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions experiment/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ def create_ossfuzz_project(self,
f'{self.benchmark.target_path}\n')

if not build_script_path or os.path.getsize(build_script_path) == 0:
return name
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked callers of this function to see if this returned name variable is being used. I didn't find any usage, hence believed it was safe to change it.

# Return the generated project path to the caller.
return generated_project_path

# Copy generated build script to generated_project_path
shutil.copyfile(
Expand All @@ -294,7 +295,8 @@ def create_ossfuzz_project(self,
with open(os.path.join(generated_project_path, 'Dockerfile'), 'a') as f:
f.write('\nCOPY agent-build.sh /src/build.sh\n')

return name
# Return the generated project path to the caller.
return generated_project_path

def _fix_generated_fuzz_target(self, ai_binary: str,
generated_oss_fuzz_project: str,
Expand Down
29 changes: 28 additions & 1 deletion stage/execution_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,34 @@ def execute(self, result_history: list[Result]) -> Result:
f'{last_result.trial:02d}.fuzz_target')
build_script_path = os.path.join(last_result.work_dirs.fuzz_targets,
f'{last_result.trial:02d}.build_script')
evaluator.create_ossfuzz_project(generated_oss_fuzz_project,
generated_project_path = evaluator.create_ossfuzz_project(generated_oss_fuzz_project,
fuzz_target_path, build_script_path)

status_path = os.path.join(last_result.work_dirs.status,
f'{last_result.trial:02}')
os.makedirs(status_path, exist_ok=True)

# Get the source code of the fuzz target and build script from the generated oss-fuzz projects.
fuzz_target_source_path = os.path.join(generated_project_path, f'{last_result.trial:02d}.fuzz_target')
Copy link
Collaborator Author

@AmPaschal AmPaschal May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could have just reused the existing fuzz_target_path. However, I wanted to actually log the version of the fuzz_target in the generated_oss_fuzz project (in case it differed with the version produced in the last_result.work_dirs.fuzz_targets path and stored in the current fuzz_target_path variables).

I could revert and use fuzz_target_path directly if necessary.


if fuzz_target_source_path and os.path.isfile(fuzz_target_source_path):
with open(fuzz_target_source_path, 'r') as f:
fuzz_target_source = f.read()
else:
fuzz_target_source = ''

build_script_source_path = os.path.join(generated_project_path, f'{last_result.trial:02d}.build_script')

if build_script_source_path and os.path.isfile(build_script_source_path):
with open(build_script_source_path, 'r') as f:
build_script_source = f.read()
else:
build_script_source = ''

# log the fuzz target and build script's source code.
self.logger.info('\nFuzz target source: \n%s\n', fuzz_target_source)
self.logger.info('\nBuild script source: \n%s\n', build_script_source)

# Try building and running the new target.

# TODO: Log build failure.
Expand Down Expand Up @@ -136,6 +157,12 @@ def execute(self, result_history: list[Result]) -> Result:
else:
run_log_content = ''

# Add fuzz_target_source and build_script_source to the report log.
run_log_content = (
f'Fuzz target source:\n{fuzz_target_source}\n'
f'Build script source:\n{build_script_source}\n'
f'{run_log_content}')

runresult = RunResult(
benchmark=benchmark,
trial=last_result.trial,
Expand Down
Loading