Skip to content

Commit

Permalink
Merge pull request #95 from kevin-valerio/main
Browse files Browse the repository at this point in the history
Building in release mode is now possible
  • Loading branch information
vanhauser-thc committed Jun 20, 2024
2 parents f364a3a + 44be82e commit 375a548
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 15 deletions.
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
2 changes: 2 additions & 0 deletions src/bin/cargo-ziggy/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,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 @@ -790,6 +791,7 @@ impl FuzzingConfig {
}

use std::fmt;

impl fmt::Display for FuzzingConfig {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
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 @@ -95,6 +95,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 @@ -111,8 +115,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 @@ -148,7 +158,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 @@ -179,7 +189,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 @@ -198,7 +210,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 @@ -224,7 +238,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 @@ -255,7 +271,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 @@ -274,7 +292,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 @@ -294,7 +314,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

0 comments on commit 375a548

Please sign in to comment.