Skip to content

Commit

Permalink
Use nonzero! macro (#2589)
Browse files Browse the repository at this point in the history
* nonzero_lit

* nonzero

* std instead of core

* a

* l

* test

* import

* api

* api

* aaaaa

* apiapi

* api

* api

* api

* mm

* api

* non zero

* FMT

* pls

* nnnaaasdfadsfafdsa

* pls

* MM

* fix

* a

* sat add

* aa

* mistake

* unreachable

* no generic

* api change

* a
  • Loading branch information
tokatoka authored Oct 18, 2024
1 parent 3b31b4d commit fda1596
Show file tree
Hide file tree
Showing 51 changed files with 282 additions and 286 deletions.
5 changes: 2 additions & 3 deletions docs/listings/baby_fuzzer/listing-04/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ extern crate libafl;
extern crate libafl_bolts;

use std::path::PathBuf;

use libafl::{
corpus::{InMemoryCorpus, OnDiskCorpus},
events::SimpleEventManager,
Expand All @@ -15,7 +14,7 @@ use libafl::{
schedulers::QueueScheduler,
state::StdState,
};
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice};
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice, nonzero};
/* ANCHOR_END: use */

fn main() {
Expand Down Expand Up @@ -77,7 +76,7 @@ fn main() {

/* ANCHOR: generator */
// Generator of printable bytearrays of max size 32
let mut generator = RandPrintablesGenerator::new(32).unwrap();
let mut generator = RandPrintablesGenerator::new(nonzero!(32));

// Generate 8 initial inputs
state
Expand Down
4 changes: 2 additions & 2 deletions docs/listings/baby_fuzzer/listing-05/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use libafl::{
schedulers::QueueScheduler,
state::StdState,
};
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice};
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice, nonzero};
use std::path::PathBuf;
/* ANCHOR_END: use */

Expand Down Expand Up @@ -105,7 +105,7 @@ fn main() {
/* ANCHOR_END: executor_with_observer */

// Generator of printable bytearrays of max size 32
let mut generator = RandPrintablesGenerator::new(32).unwrap();
let mut generator = RandPrintablesGenerator::new(nonzero!(32));

// Generate 8 initial inputs
state
Expand Down
5 changes: 3 additions & 2 deletions docs/listings/baby_fuzzer/listing-06/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* ANCHOR: use */
extern crate libafl;
extern crate libafl_bolts;
use std::num::NonZeroUsize;

use libafl::{
corpus::{InMemoryCorpus, OnDiskCorpus},
Expand All @@ -17,7 +18,7 @@ use libafl::{
stages::mutational::StdMutationalStage,
state::StdState,
};
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice};
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice, nonzero};
use std::path::PathBuf;
/* ANCHOR_END: use */

Expand Down Expand Up @@ -97,7 +98,7 @@ fn main() {
.expect("Failed to create the Executor");

// Generator of printable bytearrays of max size 32
let mut generator = RandPrintablesGenerator::new(32).unwrap();
let mut generator = RandPrintablesGenerator::new(nonzero!(32));

// Generate 8 initial inputs
state
Expand Down
4 changes: 2 additions & 2 deletions fuzzers/baby/baby_fuzzer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use libafl::{
stages::mutational::StdMutationalStage,
state::StdState,
};
use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice};
use libafl_bolts::{current_nanos, nonzero, rands::StdRand, tuples::tuple_list, AsSlice};

/// Coverage map with explicit assignments due to the lack of instrumentation
static mut SIGNALS: [u8; 16] = [0; 16];
Expand Down Expand Up @@ -116,7 +116,7 @@ pub fn main() {
.expect("Failed to create the Executor");

// Generator of printable bytearrays of max size 32
let mut generator = RandPrintablesGenerator::new(32).unwrap();
let mut generator = RandPrintablesGenerator::new(nonzero!(32));

// Generate 8 initial inputs
state
Expand Down
2 changes: 1 addition & 1 deletion fuzzers/baby/baby_fuzzer_minimizing/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn main() -> Result<(), Error> {
.expect("Failed to create the Executor");

// Generator of printable bytearrays of max size 32
let mut generator = RandPrintablesGenerator::new(32).unwrap();
let mut generator = RandPrintablesGenerator::new(nonzero!(32));

// Generate 8 initial inputs
state
Expand Down
4 changes: 2 additions & 2 deletions fuzzers/baby/baby_fuzzer_swap_differential/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use libafl::{
stages::mutational::StdMutationalStage,
state::{HasSolutions, StdState},
};
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice};
use libafl_bolts::{nonzero, rands::StdRand, tuples::tuple_list, AsSlice};
use libafl_targets::{edges_max_num, DifferentialAFLMapSwapObserver};
#[cfg(not(miri))]
use mimalloc::MiMalloc;
Expand Down Expand Up @@ -247,7 +247,7 @@ pub fn main() {
);

// Generator of printable bytearrays of max size 32
let mut generator = RandPrintablesGenerator::new(32).unwrap();
let mut generator = RandPrintablesGenerator::new(nonzero!(32));

// Generate 8 initial inputs
state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use libafl::{
state::StdState,
};
use libafl_bolts::{
nonzero,
ownedref::OwnedRefMut,
rands::StdRand,
shmem::{ShMemProvider, StdShMemProvider},
Expand Down Expand Up @@ -103,7 +104,7 @@ pub fn main() {
.expect("Failed to create the Executor");

// Generator of printable bytearrays of max size 32
let mut generator = RandPrintablesGenerator::new(32).unwrap();
let mut generator = RandPrintablesGenerator::new(nonzero!(32));

// Generate 8 initial inputs
state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use libafl::{
stages::mutational::StdMutationalStage,
state::StdState,
};
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice};
use libafl_bolts::{nonzero, rands::StdRand, tuples::tuple_list, AsSlice};
use libc::c_uchar;
extern crate libc;

Expand Down Expand Up @@ -89,7 +89,7 @@ pub fn main() {
.expect("Failed to create the Executor");

// Generator of printable bytearrays of max size 32
let mut generator = RandPrintablesGenerator::new(32).unwrap();
let mut generator = RandPrintablesGenerator::new(nonzero!(32));

// Generate 8 initial inputs
state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use libafl::{
Error,
};
use libafl_bolts::{
nonzero,
rands::StdRand,
shmem::{unix_shmem, ShMem, ShMemId, ShMemProvider},
tuples::tuple_list,
Expand Down Expand Up @@ -112,7 +113,7 @@ pub fn main() {
let mut executor = MyExecutor { shmem_id }.into_executor(tuple_list!(observer, bt_observer));

// Generator of printable bytearrays of max size 32
let mut generator = RandPrintablesGenerator::new(32).unwrap();
let mut generator = RandPrintablesGenerator::new(nonzero!(32));

// Generate 8 initial inputs
state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use libafl_bolts::shmem::StdShMemProvider;
#[cfg(target_vendor = "apple")]
use libafl_bolts::shmem::UnixShMemProvider;
use libafl_bolts::{
nonzero,
rands::StdRand,
shmem::{ShMem, ShMemProvider},
tuples::tuple_list,
Expand Down Expand Up @@ -97,7 +98,7 @@ pub fn main() {
.unwrap();

// Generator of printable bytearrays of max size 32
let mut generator = RandPrintablesGenerator::new(3).unwrap();
let mut generator = RandPrintablesGenerator::new(nonzero!(32));

// Generate 8 initial inputs
state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use libafl::{
state::StdState,
};
use libafl_bolts::{
nonzero,
ownedref::OwnedRefMut,
rands::StdRand,
shmem::{unix_shmem, ShMem, ShMemProvider},
Expand Down Expand Up @@ -122,7 +123,7 @@ pub fn main() {
.expect("Failed to create the Executor");

// Generator of printable bytearrays of max size 32
let mut generator = RandPrintablesGenerator::new(32).unwrap();
let mut generator = RandPrintablesGenerator::new(nonzero!(32));

// Generate 8 initial inputs
state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use libafl::{
stages::mutational::StdMutationalStage,
state::StdState,
};
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice};
use libafl_bolts::{nonzero, rands::StdRand, tuples::tuple_list, AsSlice};

/// Coverage map with explicit assignments due to the lack of instrumentation
static mut SIGNALS: [u8; 16] = [0; 16];
Expand Down Expand Up @@ -113,7 +113,7 @@ pub fn main() {
.expect("Failed to create the Executor");

// Generator of printable bytearrays of max size 32
let mut generator = RandPrintablesGenerator::new(32).unwrap();
let mut generator = RandPrintablesGenerator::new(nonzero!(32));

// Generate 8 initial inputs
state
Expand Down
3 changes: 2 additions & 1 deletion fuzzers/forkserver/baby_fuzzer_with_forkexecutor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use libafl::{
state::StdState,
};
use libafl_bolts::{
nonzero,
rands::StdRand,
shmem::{unix_shmem, ShMemProvider},
tuples::tuple_list,
Expand Down Expand Up @@ -115,7 +116,7 @@ pub fn main() {
.expect("Failed to create the Executor");

// Generator of printable bytearrays of max size 32
let mut generator = RandPrintablesGenerator::new(32).unwrap();
let mut generator = RandPrintablesGenerator::new(nonzero!(32));

// Generate 8 initial inputs
state
Expand Down
3 changes: 1 addition & 2 deletions fuzzers/forkserver/forkserver_libafl_cc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ pub fn main() {

// Setup a mutational stage with a basic bytes mutator
let mutator =
StdScheduledMutator::with_max_stack_pow(havoc_mutations().merge(tokens_mutations()), 6)
.unwrap();
StdScheduledMutator::with_max_stack_pow(havoc_mutations().merge(tokens_mutations()), 6);
let mut stages = tuple_list!(StdMutationalStage::new(mutator));

fuzzer
Expand Down
3 changes: 1 addition & 2 deletions fuzzers/forkserver/forkserver_simple/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ pub fn main() {

// Setup a mutational stage with a basic bytes mutator
let mutator =
StdScheduledMutator::with_max_stack_pow(havoc_mutations().merge(tokens_mutations()), 6)
.unwrap();
StdScheduledMutator::with_max_stack_pow(havoc_mutations().merge(tokens_mutations()), 6);
let mut stages = tuple_list!(StdMutationalStage::new(mutator));

fuzzer
Expand Down
6 changes: 4 additions & 2 deletions fuzzers/fuzz_anything/baby_fuzzer_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use libafl::{
state::{HasSolutions, StdState},
Fuzzer, StdFuzzer,
};
use libafl_bolts::{rands::StdRand, serdeany::RegistryBuilder, tuples::tuple_list, AsSlice};
use libafl_bolts::{
nonzero, rands::StdRand, serdeany::RegistryBuilder, tuples::tuple_list, AsSlice,
};
use wasm_bindgen::prelude::*;
use web_sys::{Performance, Window};

Expand Down Expand Up @@ -126,7 +128,7 @@ pub fn fuzz() {
.expect("Failed to create the Executor");

// Generator of printable bytearrays of max size 32
let mut generator = RandPrintablesGenerator::new(32).unwrap();
let mut generator = RandPrintablesGenerator::new(nonzero!(32));

// Generate 8 initial inputs
state
Expand Down
4 changes: 2 additions & 2 deletions fuzzers/fuzz_anything/baby_no_std/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use libafl::{
stages::mutational::StdMutationalStage,
state::StdState,
};
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice};
use libafl_bolts::{nonzero, rands::StdRand, tuples::tuple_list, AsSlice};
#[cfg(any(windows, unix))]
use libc::{abort, printf};
use static_alloc::Bump;
Expand Down Expand Up @@ -144,7 +144,7 @@ pub extern "C" fn main(_argc: isize, _argv: *const *const u8) -> isize {
.expect("Failed to create the Executor");

// Generator of printable bytearrays of max size 32
let mut generator = RandPrintablesGenerator::new(32).unwrap();
let mut generator = RandPrintablesGenerator::new(nonzero!(32));

// Generate 8 initial inputs
state
Expand Down
3 changes: 2 additions & 1 deletion fuzzers/fuzz_anything/libafl_atheris/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use libafl::{
};
use libafl_bolts::{
core_affinity::Cores,
nonzero,
rands::StdRand,
shmem::{ShMemProvider, StdShMemProvider},
tuples::{tuple_list, Merge},
Expand Down Expand Up @@ -240,7 +241,7 @@ pub extern "C" fn LLVMFuzzerRunDriver(
if state.must_load_initial_inputs() {
if input_dirs.is_empty() {
// Generator of printable bytearrays of max size 32
let mut generator = RandBytesGenerator::new(32).unwrap();
let mut generator = RandBytesGenerator::new(nonzero!(32));

// Generate 8 initial inputs
state
Expand Down
4 changes: 2 additions & 2 deletions fuzzers/fuzz_anything/push_harness/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use libafl::{
stages::mutational::StdMutationalStage,
state::StdState,
};
use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice};
use libafl_bolts::{current_nanos, nonzero, rands::StdRand, tuples::tuple_list, AsSlice};

/// Coverage map with explicit assignments due to the lack of instrumentation
static mut SIGNALS: [u8; 16] = [0; 16];
Expand Down Expand Up @@ -93,7 +93,7 @@ fn input_generator() {
.expect("Failed to create the Executor");

// Generator of printable bytearrays of max size 32
let mut generator = RandPrintablesGenerator::new(32).unwrap();
let mut generator = RandPrintablesGenerator::new(nonzero!(32));

// Generate 8 initial inputs
state
Expand Down
4 changes: 2 additions & 2 deletions fuzzers/inprocess/fuzzbench_text/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,8 @@ fn fuzz_text(
GrimoireRandomDeleteMutator::new(),
),
3,
)
.unwrap();
);

let grimoire = StdMutationalStage::transforming(grimoire_mutator);

// A minimization+queue policy to get testcasess from the corpus
Expand Down
30 changes: 14 additions & 16 deletions fuzzers/structure_aware/baby_fuzzer_custom_input/src/input.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core::num::NonZeroUsize;
use std::{
borrow::Cow,
hash::{DefaultHasher, Hash, Hasher},
Expand Down Expand Up @@ -59,20 +60,20 @@ impl CustomInput {
}

/// A generator for [`CustomInput`] used in this example
pub struct CustomInputGenerator<S: HasRand> {
pub bytes_generator: RandBytesGenerator<S>,
pub struct CustomInputGenerator {
pub bytes_generator: RandBytesGenerator,
}

impl<S: HasRand> CustomInputGenerator<S> {
impl CustomInputGenerator {
/// Creates a new [`CustomInputGenerator`]
pub fn new(max_len: usize) -> Result<Self, Error> {
Ok(Self {
bytes_generator: RandBytesGenerator::new(max_len)?,
})
pub fn new(max_len: NonZeroUsize) -> Self {
Self {
bytes_generator: RandBytesGenerator::new(max_len),
}
}
}

impl<S> Generator<CustomInput, S> for CustomInputGenerator<S>
impl<S> Generator<CustomInput, S> for CustomInputGenerator
where
S: HasRand,
{
Expand All @@ -99,15 +100,12 @@ pub struct ToggleOptionalByteArrayMutator<G> {
generator: G,
}

impl<S> ToggleOptionalByteArrayMutator<RandBytesGenerator<S>>
where
S: HasRand,
{
impl ToggleOptionalByteArrayMutator<RandBytesGenerator> {
/// Creates a new [`ToggleOptionalByteArrayMutator`]
pub fn new(length: usize) -> Result<Self, Error> {
Ok(Self {
generator: RandBytesGenerator::new(length)?,
})
pub fn new(length: NonZeroUsize) -> Self {
Self {
generator: RandBytesGenerator::new(length),
}
}
}

Expand Down
Loading

0 comments on commit fda1596

Please sign in to comment.