Skip to content
Merged
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ cli = [
"cargo_metadata",
"clap",
"console",
"dep:serde",
"dep:serde_json",
"glob",
"indicatif",
"libc",
Expand Down Expand Up @@ -60,6 +62,8 @@ indicatif = { version = "0.18.4", optional = true }
libc = { version = "0.2.183", optional = true }
rayon = { version = "1.11.0", optional = true }
semver = { version = "1.0.27", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
serde_json = { version = "1.0", optional = true }
signal-hook = { version = "0.4.3", optional = true }
strip-ansi-escapes = { version = "0.2.1", optional = true }
target-triple = { version = "1.0.0", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion examples/asan/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fn main() {
return;
}
if data[0] == b'f' && data[1] == b'u' && data[2] == b'z' && data[3] == b'z' {
let xs = [0, 1, 2, 3];
let xs = std::hint::black_box([0, 1, 2, 3]);
let _y = std::hint::black_box(unsafe { *xs.as_ptr().add(4) });
}
});
Expand Down
9 changes: 8 additions & 1 deletion src/bin/cargo-ziggy/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,14 @@ impl Build {
let run = common
.cargo()
.args(["hfuzz", "build", "--bin", &cx.bin_target])
.env("CARGO_TARGET_DIR", cx.target_dir.join("honggfuzz"))
.env(
"CARGO_TARGET_DIR",
cx.target_dir.join(if self.asan {
"honggfuzz-asan"
} else {
"honggfuzz"
}),
)
.envs(honggfuzz_envs(self.asan))
.stdout(process::Stdio::piped())
.spawn()?
Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo-ziggy/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl Clean {
clean("afl", Some(target_triple::TARGET), false)?;
// honggfuzz uses --target=host
clean("honggfuzz", Some(target_triple::TARGET), true)?;
clean("honggfuzz-asan", Some(target_triple::TARGET), true)?;
// coverage (from ziggy cover)
clean("coverage", None, false)?;
// runner (from ziggy run)
Expand Down
34 changes: 21 additions & 13 deletions src/bin/cargo-ziggy/fuzz.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
Build, Common, Cover, Fuzz, FuzzingEngines, Minimize,
util::{Context, ContextView},
util::{Context, ContextView, TimeoutArg},
};
use anyhow::{Context as _, Error, Result, anyhow, bail};
use console::{Term, style};
Expand Down Expand Up @@ -100,6 +100,12 @@ impl Fuzz {
};
let cx_view = cx.view(common);

if self.asan && self.memory_limit.is_some() {
bail!(
"--memory-limit and --asan are incompatible, because ASan reserves a large shadow mapping"
);
}

if self.binary.is_none() {
let build = Build {
no_afl: !self.afl(),
Expand Down Expand Up @@ -518,11 +524,6 @@ impl Fuzz {
22 => "-l3at",
_ => "-c-", // disable Cmplog, needs AFL++ 4.08a
};
// AFL timeout is in ms so we convert the value
let timeout_option_afl = match self.timeout {
Some(t) => format!("-t{}", t * 1000),
None => String::new(),
};
let memory_option_afl = match &self.memory_limit {
Some(m) => format!("-m{m}"),
None => String::new(),
Expand Down Expand Up @@ -589,14 +590,14 @@ impl Fuzz {
&format!("-o{}/afl", paths.output_target),
&format!("-g{}", self.min_length),
&format!("-G{}", self.max_length),
&TimeoutArg::from(self.timeout).afl_arg(),
&use_shared_corpus,
&use_initial_corpus_dir,
old_queue_cycling,
cmplog_options,
mopt_mutator,
mutation_option,
input_format_option,
&timeout_option_afl,
&memory_option_afl,
&dictionary_option,
]
Expand Down Expand Up @@ -641,8 +642,9 @@ impl Fuzz {
run_args.push_str(&format!(" -F{}", self.max_length));
run_args.push_str(&format!(" --dynamic_input={}/queue", paths.output_target));
run_args.push_str(" --tmout_sigvtalrm");
if let Some(t) = self.timeout {
run_args.push_str(&format!(" -t{t}"));
{
run_args.push(' ');
run_args.push_str(&TimeoutArg::from(self.timeout).honggfuzz_arg());
}
if let Some(d) = &self.dictionary {
run_args.push_str(&format!(" -w{}", d.display()));
Expand All @@ -653,6 +655,11 @@ impl Fuzz {

run_args
};
let hfuzz_target = if self.asan {
"honggfuzz-asan"
} else {
"honggfuzz"
};

let log = File::create(format!("{}/logs/honggfuzz.log", paths.output_target))?;

Expand All @@ -670,7 +677,7 @@ impl Fuzz {
),
"/dev/null",
])
.env("CARGO_TARGET_DIR", cx.target_dir().join("honggfuzz"))
.env("CARGO_TARGET_DIR", cx.target_dir().join(hfuzz_target))
.envs(crate::build::honggfuzz_envs(self.asan))
.env(
"HFUZZ_WORKSPACE",
Expand Down Expand Up @@ -745,8 +752,9 @@ impl Fuzz {
output_corpus: PathBuf::from(minimized_corpus),
ziggy_output: self.ziggy_output.clone(),
jobs: self.jobs,
timeout: self.timeout.unwrap_or(5000),
timeout: self.timeout,
engine,
release: self.release,
};
match minimization_args.minimize(common) {
Ok(()) => {
Expand All @@ -769,8 +777,8 @@ impl Fuzz {
new_corpus_size
))?;
}
Err(_) => {
bail!("Please check the logs, this might be an oom error");
Err(e) => {
return Err(e).context("Please check the logs, this might be an oom error");
}
}
Ok(())
Expand Down
Loading