Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use nonzero_lit #2589

Merged
merged 35 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 32 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
3 changes: 1 addition & 2 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 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(32);

// Generate 8 initial inputs
state
Expand Down
2 changes: 1 addition & 1 deletion docs/listings/baby_fuzzer/listing-05/src/main.rs
Original file line number Diff line number Diff line change
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(32);

// Generate 8 initial inputs
state
Expand Down
3 changes: 2 additions & 1 deletion 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 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(32);

// Generate 8 initial inputs
state
Expand Down
2 changes: 1 addition & 1 deletion fuzzers/baby/baby_fuzzer/src/main.rs
Original file line number Diff line number Diff line change
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(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(32);

// Generate 8 initial inputs
state
Expand Down
2 changes: 1 addition & 1 deletion fuzzers/baby/baby_fuzzer_swap_differential/src/main.rs
Original file line number Diff line number Diff line change
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(32);

// Generate 8 initial inputs
state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,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(32);

// Generate 8 initial inputs
state
Expand Down
Original file line number Diff line number Diff line change
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(32);

// Generate 8 initial inputs
state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,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(32);

// Generate 8 initial inputs
state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,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(32);

// Generate 8 initial inputs
state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,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(32);

// Generate 8 initial inputs
state
Expand Down
Original file line number Diff line number Diff line change
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(32);

// Generate 8 initial inputs
state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,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(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
2 changes: 1 addition & 1 deletion fuzzers/fuzz_anything/baby_fuzzer_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,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(32);

// Generate 8 initial inputs
state
Expand Down
2 changes: 1 addition & 1 deletion fuzzers/fuzz_anything/baby_no_std/src/main.rs
Original file line number Diff line number Diff line change
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(32);

// Generate 8 initial inputs
state
Expand Down
2 changes: 1 addition & 1 deletion fuzzers/fuzz_anything/libafl_atheris/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,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(32);

// Generate 8 initial inputs
state
Expand Down
2 changes: 1 addition & 1 deletion fuzzers/fuzz_anything/push_harness/src/main.rs
Original file line number Diff line number Diff line change
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(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
20 changes: 10 additions & 10 deletions fuzzers/structure_aware/baby_fuzzer_custom_input/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ impl CustomInput {

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

impl<S: HasRand> CustomInputGenerator<S> {
/// 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: usize) -> Self {
Self {
bytes_generator: RandBytesGenerator::new(max_len),
}
}
}

Expand Down Expand Up @@ -99,15 +99,15 @@ pub struct ToggleOptionalByteArrayMutator<G> {
generator: G,
}

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

Expand Down
7 changes: 2 additions & 5 deletions fuzzers/structure_aware/baby_fuzzer_custom_input/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ pub fn main() {
.expect("Failed to create the Executor");

// Generator of printable bytearrays of max size 32
let mut generator =
CustomInputGenerator::new(1).expect("Failed to create our custom input generator");
let mut generator = CustomInputGenerator::new(1);

// Generate 8 initial inputs
state
Expand Down Expand Up @@ -183,9 +182,7 @@ pub fn main() {
// Then, mutators for the optional byte array, these return MutationResult::Skipped if the part is not present
.merge(optional_mapped_mutators)
// A custom mutator that sets the optional byte array to None if present, and generates a random byte array of length 1 if it is not
.prepend(
ToggleOptionalByteArrayMutator::new(1).expect("Failed to create bytearray mutator"),
)
.prepend(ToggleOptionalByteArrayMutator::new(1))
// Finally, a custom mutator that toggles the boolean part of the input
.prepend(ToggleBooleanMutator);

Expand Down
3 changes: 1 addition & 2 deletions fuzzers/structure_aware/baby_fuzzer_gramatron/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ pub fn main() {
GramatronRecursionMutator::new()
),
2,
)
.unwrap();
);
let mut stages = tuple_list!(StdMutationalStage::new(mutator));

fuzzer
Expand Down
5 changes: 2 additions & 3 deletions fuzzers/structure_aware/baby_fuzzer_grimoire/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub fn main() {
.expect("Failed to create the Executor");

// Setup a mutational stage with a basic bytes mutator
let mutator = StdScheduledMutator::with_max_stack_pow(havoc_mutations(), 2).unwrap();
let mutator = StdScheduledMutator::with_max_stack_pow(havoc_mutations(), 2);
let grimoire_mutator = StdScheduledMutator::with_max_stack_pow(
tuple_list!(
GrimoireExtensionMutator::new(),
Expand All @@ -150,8 +150,7 @@ pub fn main() {
GrimoireRandomDeleteMutator::new(),
),
3,
)
.unwrap();
);
let mut stages = tuple_list!(
generalization,
StdMutationalStage::new(mutator),
Expand Down
3 changes: 1 addition & 2 deletions fuzzers/structure_aware/baby_fuzzer_nautilus/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ pub fn main() {
NautilusSpliceMutator::new(&context),
),
2,
)
.unwrap();
);
let mut stages = tuple_list!(StdMutationalStage::new(mutator));

fuzzer
Expand Down
2 changes: 1 addition & 1 deletion fuzzers/structure_aware/baby_fuzzer_tokens/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub fn main() {
.expect("Failed to create the Executor");

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

println!("Decoder {:?} ...", &encoder_decoder);
Expand Down
3 changes: 1 addition & 2 deletions fuzzers/structure_aware/nautilus_sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ pub extern "C" fn libafl_main() {
NautilusSpliceMutator::new(&context),
),
2,
)
.unwrap();
);

if let Some(conv) = event_converter.take() {
let mut stages = tuple_list!(
Expand Down
7 changes: 5 additions & 2 deletions libafl/src/common/nautilus/grammartec/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use alloc::{borrow::ToOwned, string::String, vec::Vec};
use core::num::NonZero;

use hashbrown::HashMap;
use libafl_bolts::rands::{Rand, RomuDuoJrRand};
use libafl_bolts::{
nonzero,
rands::{Rand, RomuDuoJrRand},
};
use pyo3::prelude::PyObject;

use super::{
Expand Down Expand Up @@ -265,7 +268,7 @@ impl Context {
.take_while(move |r| self.rules_to_min_size[*r] <= max_len)
.filter(move |r| {
self.rules_to_num_options[*r] > 1
|| rand.below(NonZero::new(100).unwrap()) <= p_include_short_rules
|| rand.below(nonzero!(100)) <= p_include_short_rules
})
}

Expand Down
Loading
Loading