Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/cov-worker
Browse files Browse the repository at this point in the history
  • Loading branch information
louismerlin committed Sep 9, 2024
2 parents d0d12e5 + 1aa9693 commit 15fbb64
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 19 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ cli = [
"cargo_metadata",
]
coverage = ["fork", "libc"]

[lints.clippy]
needless_doctest_main = "allow"
3 changes: 3 additions & 0 deletions examples/url/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ publish = false
[dependencies]
url = "2.5.0"
ziggy = { path = "../../", default-features = false }

[features]
fuzzing = []
2 changes: 1 addition & 1 deletion examples/url/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// could assert that a certain value satisfies a property.
fn invariant_fuzz(data: &str) {
if let Ok(parsed) = url::Url::parse(data) {
#[cfg(not(fuzzing))]
#[cfg(not(feature = "fuzzing"))]
println!("{data} => {parsed}");
// We assert that the string representation of the URL always contains a ':'
// character.
Expand Down
29 changes: 22 additions & 7 deletions src/bin/cargo-ziggy/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,22 @@ impl Build {

if !self.no_afl {
eprintln!(" {} afl", style("Building").red().bold());
let mut afl_args = vec![
"afl",
"build",
"--features=ziggy/afl",
"--target-dir=target/afl",
];

// Add the --release argument if self.release is true
if self.release {
afl_args.push("--release");
info!("Building in release mode");
}

// Second fuzzer we build: AFL++
let run = process::Command::new(cargo.clone())
.args([
"afl",
"build",
"--features=ziggy/afl",
"--target-dir=target/afl",
])
.args(afl_args)
.env("AFL_QUIET", "1")
.env("AFL_LLVM_CMPGLOG", "1") // for afl.rs feature "plugins"
.env("RUSTFLAGS", env::var("RUSTFLAGS").unwrap_or_default())
Expand All @@ -46,9 +53,17 @@ impl Build {
if !self.no_honggfuzz {
eprintln!(" {} honggfuzz", style("Building").red().bold());

let mut hfuzz_args = vec!["hfuzz", "build"];

// Add the --release argument if self.release is true
if self.release {
hfuzz_args.push("--release");
info!("Building in release mode");
}

// Third fuzzer we build: Honggfuzz
let run = process::Command::new(cargo)
.args(["hfuzz", "build"])
.args(hfuzz_args)
.env("CARGO_TARGET_DIR", "./target/honggfuzz")
.env("HFUZZ_BUILD_ARGS", "--features=ziggy/honggfuzz")
.env("RUSTFLAGS", env::var("RUSTFLAGS").unwrap_or_default())
Expand Down
4 changes: 3 additions & 1 deletion src/bin/cargo-ziggy/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl Fuzz {
let build = Build {
no_afl: !self.afl(),
no_honggfuzz: !self.honggfuzz(),
release: self.release,
};
build.build().context("Failed to build the fuzzers")?;

Expand Down Expand Up @@ -934,6 +935,7 @@ impl FuzzingConfig {
}

use std::fmt;

impl fmt::Display for FuzzingConfig {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
Expand All @@ -942,7 +944,7 @@ impl fmt::Display for FuzzingConfig {

pub fn kill_subprocesses_recursively(pid: &str) -> Result<(), Error> {
let subprocesses = process::Command::new("pgrep")
.arg(&format!("-P{pid}"))
.arg(format!("-P{pid}"))
.output()?;

for subprocess in std::str::from_utf8(&subprocesses.stdout)?.split('\n') {
Expand Down
38 changes: 30 additions & 8 deletions src/bin/cargo-ziggy/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ pub struct Build {
/// No honggfuzz (Fuzz only with AFL++)
#[clap(long = "no-honggfuzz", action)]
no_honggfuzz: bool,

/// Compile in release mode (--release)
#[clap(long = "release", action)]
release: bool,
}

#[derive(Args)]
Expand All @@ -112,8 +116,14 @@ pub struct Fuzz {
#[clap(short, long, value_parser, value_name = "DIR")]
initial_corpus: Option<PathBuf>,

/// Compile in release mode (--release)
#[clap(long = "release", action)]
release: bool,

/// Fuzzers output directory
#[clap(short, long, env="ZIGGY_OUTPUT", value_parser, value_name = "DIR", default_value=DEFAULT_OUTPUT_DIR)]
#[clap(
short, long, env = "ZIGGY_OUTPUT", value_parser, value_name = "DIR", default_value = DEFAULT_OUTPUT_DIR
)]
ziggy_output: PathBuf,

/// Number of concurent fuzzing jobs
Expand Down Expand Up @@ -149,7 +159,7 @@ pub struct Fuzz {
no_honggfuzz: bool,

// This value helps us create a global timer for our display
#[clap(skip=std::time::Instant::now())]
#[clap(skip = std::time::Instant::now())]
start_time: std::time::Instant,

/// Pass flags to AFL++ directly
Expand Down Expand Up @@ -188,7 +198,9 @@ pub struct Run {
recursive: bool,

/// Fuzzers output directory
#[clap(short, long, env="ZIGGY_OUTPUT", value_parser, value_name = "DIR", default_value=DEFAULT_OUTPUT_DIR)]
#[clap(
short, long, env = "ZIGGY_OUTPUT", value_parser, value_name = "DIR", default_value = DEFAULT_OUTPUT_DIR
)]
ziggy_output: PathBuf,
}

Expand All @@ -207,7 +219,9 @@ pub struct Minimize {
output_corpus: PathBuf,

/// Fuzzers output directory
#[clap(short, long, env="ZIGGY_OUTPUT", value_parser, value_name = "DIR", default_value=DEFAULT_OUTPUT_DIR)]
#[clap(
short, long, env = "ZIGGY_OUTPUT", value_parser, value_name = "DIR", default_value = DEFAULT_OUTPUT_DIR
)]
ziggy_output: PathBuf,

/// Number of concurent minimizing jobs (AFL++ only)
Expand All @@ -233,7 +247,9 @@ pub struct Cover {
input: PathBuf,

/// Fuzzers output directory
#[clap(short, long, env="ZIGGY_OUTPUT", value_parser, value_name = "DIR", default_value=DEFAULT_OUTPUT_DIR)]
#[clap(
short, long, env = "ZIGGY_OUTPUT", value_parser, value_name = "DIR", default_value = DEFAULT_OUTPUT_DIR
)]
ziggy_output: PathBuf,

/// Source directory of covered code
Expand Down Expand Up @@ -264,7 +280,9 @@ pub struct Plot {
output: PathBuf,

/// Fuzzers output directory
#[clap(short, long, env="ZIGGY_OUTPUT", value_parser, value_name = "DIR", default_value=DEFAULT_OUTPUT_DIR)]
#[clap(
short, long, env = "ZIGGY_OUTPUT", value_parser, value_name = "DIR", default_value = DEFAULT_OUTPUT_DIR
)]
ziggy_output: PathBuf,
}

Expand All @@ -283,7 +301,9 @@ pub struct Triage {
jobs: u32,

/// Fuzzers output directory
#[clap(short, long, env="ZIGGY_OUTPUT", value_parser, value_name = "DIR", default_value=DEFAULT_OUTPUT_DIR)]
#[clap(
short, long, env = "ZIGGY_OUTPUT", value_parser, value_name = "DIR", default_value = DEFAULT_OUTPUT_DIR
)]
ziggy_output: PathBuf,
/* future feature, wait for casr
/// Crash directory to be sourced from
Expand All @@ -303,7 +323,9 @@ pub struct AddSeeds {
input: PathBuf,

/// Fuzzers output directory
#[clap(short, long, env="ZIGGY_OUTPUT", value_parser, value_name = "DIR", default_value=DEFAULT_OUTPUT_DIR)]
#[clap(
short, long, env = "ZIGGY_OUTPUT", value_parser, value_name = "DIR", default_value = DEFAULT_OUTPUT_DIR
)]
ziggy_output: PathBuf,
}

Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo-ziggy/minimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ impl Minimize {
let build = Build {
no_afl: self.engine == FuzzingEngines::Honggfuzz,
no_honggfuzz: self.engine == FuzzingEngines::AFLPlusPlus,
release: false,
};
build.build().context("Failed to build the fuzzers")?;

Expand Down
2 changes: 1 addition & 1 deletion tests/arbitrary_fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{

fn kill_subprocesses_recursively(pid: &str) {
let subprocesses = process::Command::new("pgrep")
.arg(&format!("-P{pid}"))
.arg(format!("-P{pid}"))
.output()
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion tests/url_fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{

fn kill_subprocesses_recursively(pid: &str) {
let subprocesses = process::Command::new("pgrep")
.arg(&format!("-P{pid}"))
.arg(format!("-P{pid}"))
.output()
.unwrap();

Expand Down

0 comments on commit 15fbb64

Please sign in to comment.