-
Notifications
You must be signed in to change notification settings - Fork 127
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
Add sample Python auto generation #205
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,13 @@ def _pre_build_check(self, target_path: str, | |
return False | ||
return True | ||
|
||
def build_and_run_python(self, generated_project: str, target_path: str): | ||
build_result = BuildResult() | ||
|
||
self.build_target_local(generated_project, | ||
"/tmp/log.txt", | ||
language='python') | ||
|
||
def build_and_run(self, generated_project: str, target_path: str, | ||
iteration: int) -> tuple[BuildResult, Optional[RunResult]]: | ||
"""Builds and runs the fuzz target for fuzzing.""" | ||
|
@@ -145,6 +152,36 @@ def build_and_run(self, generated_project: str, target_path: str, | |
generated_project, benchmark_target_name)) | ||
return build_result, run_result | ||
|
||
def run_target_local_python(self, generated_project: str, target_name: str, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is very similar to We should find some better way to refactor things so there's less duplication here. One simple way I can think of now is to perhaps factor out a general |
||
log_path: str): | ||
"""Runs a target in the fixed target directory.""" | ||
# If target name is not overridden, use the basename of the target path | ||
# in the Dockerfile. | ||
print(f'Running {target_name}') | ||
command = [ | ||
'python3', 'infra/helper.py', 'run_fuzzer', generated_project, | ||
target_name, '--' | ||
] + self._libfuzzer_args() | ||
|
||
with open(log_path, 'w') as f: | ||
proc = sp.Popen(command, | ||
stdin=sp.DEVNULL, | ||
stdout=f, | ||
stderr=sp.STDOUT, | ||
cwd=oss_fuzz_checkout.OSS_FUZZ_DIR) | ||
|
||
# TODO(ochang): Handle the timeout exception. | ||
try: | ||
proc.wait(timeout=self.run_timeout + 5) | ||
except sp.TimeoutExpired: | ||
print(f'{generated_project} timed out during fuzzing.') | ||
# Try continuing and parsing the logs even in case of timeout. | ||
|
||
if proc.returncode != 0: | ||
print(f'********** Failed to run {generated_project}. **********') | ||
else: | ||
print(f'Successfully run {generated_project}.') | ||
|
||
def run_target_local(self, generated_project: str, benchmark_target_name: str, | ||
log_path: str): | ||
"""Runs a target in the fixed target directory.""" | ||
|
@@ -179,7 +216,8 @@ def run_target_local(self, generated_project: str, benchmark_target_name: str, | |
def build_target_local(self, | ||
generated_project: str, | ||
log_path: str, | ||
sanitizer: str = 'address') -> bool: | ||
sanitizer: str = 'address', | ||
language: str = 'cpp') -> bool: | ||
"""Builds a target with OSS-Fuzz.""" | ||
print(f'Building {generated_project} with {sanitizer}') | ||
command = [ | ||
|
@@ -199,6 +237,14 @@ def build_target_local(self, | |
print(f'Failed to build image for {generated_project}') | ||
return False | ||
|
||
if language == 'python': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What breaks if we let this run through the existing code from line 248 instead? IS there a way to make this work by changing the env vars being set there instead? |
||
command = 'python3 infra/helper.py build_fuzzers %s' % (generated_project) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use fstrings here to be consistent? |
||
try: | ||
sp.check_call(command, shell=True, cwd=oss_fuzz_checkout.OSS_FUZZ_DIR) | ||
except sp.CalledProcessError: | ||
return False | ||
return True | ||
|
||
outdir = get_outdir(generated_project) | ||
command = [ | ||
'docker', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Python auto-gen | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: can we place this in |
||
|
||
Logic for auto-generating python fuzzers. | ||
|
||
Sample: | ||
|
||
```sh | ||
python3 -m python_fuzzgen.build -r https://github.com/html5lib/html5lib-python -l mylog1.txt -m 50 | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid adding language specific methods here? We should ideally make this class language agnostic.