Skip to content

Commit

Permalink
aflplusplus-persistent is not supported on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Sep 30, 2024
1 parent 277cf93 commit 13a16d5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
17 changes: 12 additions & 5 deletions cargo-test-fuzz/src/fuzzer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
use super::{Executable, TestFuzz};
use anyhow::Result;
use anyhow::{ensure, Result};
use internal::Fuzzer;
use semver::Version;
use std::{path::Path, process::Command};

mod impls;

pub(super) fn instantiate(fuzzer: Fuzzer) -> &'static dyn Interface {
pub(super) fn instantiate(fuzzer: Fuzzer) -> Result<&'static dyn Interface> {
match fuzzer {
Fuzzer::Aflplusplus => impls::aflplusplus::instantiate(false),
Fuzzer::AflplusplusPersistent => impls::aflplusplus::instantiate(true),
Fuzzer::Libfuzzer => impls::libfuzzer::instantiate(),
Fuzzer::Aflplusplus => Ok(impls::aflplusplus::instantiate(false)),
Fuzzer::AflplusplusPersistent => {
// smoelius: https://github.com/AFLplusplus/AFLplusplus/blob/7b40d7b9420b2e3adb7d9afa88610199718dedba/include/forkserver.h#L114-L118
ensure!(
cfg!(not(target_os = "macos")),
"`aflplusplus-persistent` is not supported on macOS"
);
Ok(impls::aflplusplus::instantiate(true))
}
Fuzzer::Libfuzzer => Ok(impls::libfuzzer::instantiate()),
}
}

Expand Down
2 changes: 1 addition & 1 deletion cargo-test-fuzz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ fn run(opts: TestFuzz) -> Result<()> {
};

let fuzzer_env = fuzzer()?;
let fuzzer = fuzzer::instantiate(opts.fuzzer.unwrap_or(fuzzer_env));
let fuzzer = fuzzer::instantiate(opts.fuzzer.unwrap_or(fuzzer_env))?;

if let Some(object) = opts.replay {
ensure!(
Expand Down
2 changes: 1 addition & 1 deletion internal/src/fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use strum_macros::{Display, EnumIter};
// command line option. Hence, cargo-test-fuzz needs to know all available fuzzers. This is unlike
// the Serde format, which the user selects via a Cargo feature.
#[derive(
Clone, Copy, Debug, Display, Deserialize, EnumIter, PartialEq, Eq, Serialize, ValueEnum,
Clone, Copy, Debug, Deserialize, Display, EnumIter, PartialEq, Eq, Serialize, ValueEnum,
)]
#[remain::sorted]
pub enum Fuzzer {
Expand Down
11 changes: 8 additions & 3 deletions test-fuzz/tests/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enum SerdeFormat {
Cbor4ii,
}

#[derive(Clone, Copy, Debug, Display, EnumIter)]
#[derive(Clone, Copy, Debug, Display, EnumIter, Eq, PartialEq)]
enum Environment {
UbuntuLatest,
MacosLatest,
Expand All @@ -31,8 +31,8 @@ fn matrix() {
let expecteds = std::iter::repeat(
Fuzzer::iter()
.cartesian_product(Environment::iter())
.filter(|(fuzzer, environment)| {
*fuzzer != Fuzzer::AflplusplusPersistent || *environment != Environment::MacosLatest
.filter(|&(fuzzer, environment)| {
fuzzer != Fuzzer::AflplusplusPersistent || environment != Environment::MacosLatest
}),
)
.take(2)
Expand All @@ -58,6 +58,11 @@ fn matrix() {
for (expected, actual) in expecteds.zip(actuals) {
let ((expected_fuzzer, expected_environment), (expected_serde_format, expected_toolchain)) =
expected;
if expected_fuzzer == Fuzzer::AflplusplusPersistent
&& expected_environment == Environment::MacosLatest
{
continue;
}
assert_eq!(
expected_fuzzer.to_string().to_kebab_case(),
actual["fuzzer"].as_str().unwrap()
Expand Down

0 comments on commit 13a16d5

Please sign in to comment.