Skip to content
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

fuzzer: add a cargo-bolero fuzz target type #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
53 changes: 36 additions & 17 deletions fuzzers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,23 +503,42 @@ def start(self, corpus: Corpus) -> None:
# Spin up the fuzzer process itself
# libfuzzer will kill the process if it takes more than -timeout number of seconds.
# nayduck can sigstop the fuzzing process for ~2 hours at most, so 8000s should be ok.
self.proc = subprocess.Popen( # pylint: disable=consider-using-with
[
'cargo',
'fuzz',
'run',
self.target['runner'],
'--',
str(corpus.corpus_for(self.target)),
str(corpus.artifacts_for(self.target)),
f'-artifact_prefix={corpus.artifacts_for(self.target)}/',
'-timeout=8000',
] + self.target['flags'],
cwd=self.repo_dir / self.target['crate'],
start_new_session=True,
stdout=self.log_file,
stderr=subprocess.STDOUT,
)
flags = ['-timeout=8000'] + self.target['flags']
if self.target.get('type') == 'bolero':
self.proc = subprocess.Popen(
[
'cargo',
'bolero',
'test',
'--fake-nightly-toolchain',
f'--corpus-dir={corpus.corpus_for(self.target)}',
f'--crashes-dir={corpus.artifacts_for(self.target)}',
'-p',
self.target['crate'],
self.target['runner'],
] + [f'--engine-args="{flag}"' for flag in flags],
cwd = self.repo_dir,
start_new_session = True,
stdout = self.log_file,
stderr = subprocess.STDOUT,
)
else:
self.proc = subprocess.Popen( # pylint: disable=consider-using-with
[
'cargo',
'fuzz',
'run',
self.target['runner'],
'--',
str(corpus.corpus_for(self.target)),
str(corpus.artifacts_for(self.target)),
f'-artifact_prefix={corpus.artifacts_for(self.target)}/',
] + flags,
cwd=self.repo_dir / self.target['crate'],
start_new_session=True,
stdout=self.log_file,
stderr=subprocess.STDOUT,
)
Comment on lines +507 to +541
Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively:

Suggested change
if self.target.get('type') == 'bolero':
self.proc = subprocess.Popen(
[
'cargo',
'bolero',
'test',
'--fake-nightly-toolchain',
f'--corpus-dir={corpus.corpus_for(self.target)}',
f'--crashes-dir={corpus.artifacts_for(self.target)}',
'-p',
self.target['crate'],
self.target['runner'],
] + [f'--engine-args="{flag}"' for flag in flags],
cwd = self.repo_dir,
start_new_session = True,
stdout = self.log_file,
stderr = subprocess.STDOUT,
)
else:
self.proc = subprocess.Popen( # pylint: disable=consider-using-with
[
'cargo',
'fuzz',
'run',
self.target['runner'],
'--',
str(corpus.corpus_for(self.target)),
str(corpus.artifacts_for(self.target)),
f'-artifact_prefix={corpus.artifacts_for(self.target)}/',
] + flags,
cwd=self.repo_dir / self.target['crate'],
start_new_session=True,
stdout=self.log_file,
stderr=subprocess.STDOUT,
)
if self.target.get('type') == 'bolero':
cmd = [
'cargo',
'bolero',
'test',
'--fake-nightly-toolchain',
f'--corpus-dir={corpus.corpus_for(self.target)}',
f'--crashes-dir={corpus.artifacts_for(self.target)}',
'-p',
self.target['crate'],
self.target['runner'],
] + [f'--engine-args="{flag}"' for flag in flags]
cwd = self.repo_dir
else:
cmd = [
'cargo',
'fuzz',
'run',
self.target['runner'],
'--',
str(corpus.corpus_for(self.target)),
str(corpus.artifacts_for(self.target)),
f'-artifact_prefix={corpus.artifacts_for(self.target)}/',
] + flags
cwd = self.repo_dir / self.target['crate']
self.proc = subprocess.Popen( # pylint: disable=consider-using-with
cmd,
cwd=cwd,
start_new_session=True,
stdout=self.log_file,
stderr=subprocess.STDOUT,
)


def check_if_crashed(self) -> bool:
"""Checks if the current process has crashed. Returns True if it stopped.
Expand Down