Skip to content

Commit fda1596

Browse files
authored
Use nonzero! macro (#2589)
* 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
1 parent 3b31b4d commit fda1596

File tree

51 files changed

+282
-286
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+282
-286
lines changed

docs/listings/baby_fuzzer/listing-04/src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ extern crate libafl;
33
extern crate libafl_bolts;
44

55
use std::path::PathBuf;
6-
76
use libafl::{
87
corpus::{InMemoryCorpus, OnDiskCorpus},
98
events::SimpleEventManager,
@@ -15,7 +14,7 @@ use libafl::{
1514
schedulers::QueueScheduler,
1615
state::StdState,
1716
};
18-
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice};
17+
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice, nonzero};
1918
/* ANCHOR_END: use */
2019

2120
fn main() {
@@ -77,7 +76,7 @@ fn main() {
7776

7877
/* ANCHOR: generator */
7978
// Generator of printable bytearrays of max size 32
80-
let mut generator = RandPrintablesGenerator::new(32).unwrap();
79+
let mut generator = RandPrintablesGenerator::new(nonzero!(32));
8180

8281
// Generate 8 initial inputs
8382
state

docs/listings/baby_fuzzer/listing-05/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use libafl::{
1515
schedulers::QueueScheduler,
1616
state::StdState,
1717
};
18-
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice};
18+
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice, nonzero};
1919
use std::path::PathBuf;
2020
/* ANCHOR_END: use */
2121

@@ -105,7 +105,7 @@ fn main() {
105105
/* ANCHOR_END: executor_with_observer */
106106

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

110110
// Generate 8 initial inputs
111111
state

docs/listings/baby_fuzzer/listing-06/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* ANCHOR: use */
22
extern crate libafl;
33
extern crate libafl_bolts;
4+
use std::num::NonZeroUsize;
45

56
use libafl::{
67
corpus::{InMemoryCorpus, OnDiskCorpus},
@@ -17,7 +18,7 @@ use libafl::{
1718
stages::mutational::StdMutationalStage,
1819
state::StdState,
1920
};
20-
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice};
21+
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice, nonzero};
2122
use std::path::PathBuf;
2223
/* ANCHOR_END: use */
2324

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

99100
// Generator of printable bytearrays of max size 32
100-
let mut generator = RandPrintablesGenerator::new(32).unwrap();
101+
let mut generator = RandPrintablesGenerator::new(nonzero!(32));
101102

102103
// Generate 8 initial inputs
103104
state

fuzzers/baby/baby_fuzzer/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use libafl::{
2020
stages::mutational::StdMutationalStage,
2121
state::StdState,
2222
};
23-
use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice};
23+
use libafl_bolts::{current_nanos, nonzero, rands::StdRand, tuples::tuple_list, AsSlice};
2424

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

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

121121
// Generate 8 initial inputs
122122
state

fuzzers/baby/baby_fuzzer_minimizing/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub fn main() -> Result<(), Error> {
8686
.expect("Failed to create the Executor");
8787

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

9191
// Generate 8 initial inputs
9292
state

fuzzers/baby/baby_fuzzer_swap_differential/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use libafl::{
2323
stages::mutational::StdMutationalStage,
2424
state::{HasSolutions, StdState},
2525
};
26-
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice};
26+
use libafl_bolts::{nonzero, rands::StdRand, tuples::tuple_list, AsSlice};
2727
use libafl_targets::{edges_max_num, DifferentialAFLMapSwapObserver};
2828
#[cfg(not(miri))]
2929
use mimalloc::MiMalloc;
@@ -247,7 +247,7 @@ pub fn main() {
247247
);
248248

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

252252
// Generate 8 initial inputs
253253
state

fuzzers/baby/backtrace_baby_fuzzers/c_code_with_fork_executor/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use libafl::{
1717
state::StdState,
1818
};
1919
use libafl_bolts::{
20+
nonzero,
2021
ownedref::OwnedRefMut,
2122
rands::StdRand,
2223
shmem::{ShMemProvider, StdShMemProvider},
@@ -103,7 +104,7 @@ pub fn main() {
103104
.expect("Failed to create the Executor");
104105

105106
// Generator of printable bytearrays of max size 32
106-
let mut generator = RandPrintablesGenerator::new(32).unwrap();
107+
let mut generator = RandPrintablesGenerator::new(nonzero!(32));
107108

108109
// Generate 8 initial inputs
109110
state

fuzzers/baby/backtrace_baby_fuzzers/c_code_with_inprocess_executor/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use libafl::{
1616
stages::mutational::StdMutationalStage,
1717
state::StdState,
1818
};
19-
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice};
19+
use libafl_bolts::{nonzero, rands::StdRand, tuples::tuple_list, AsSlice};
2020
use libc::c_uchar;
2121
extern crate libc;
2222

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

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

9494
// Generate 8 initial inputs
9595
state

fuzzers/baby/backtrace_baby_fuzzers/command_executor/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use libafl::{
2525
Error,
2626
};
2727
use libafl_bolts::{
28+
nonzero,
2829
rands::StdRand,
2930
shmem::{unix_shmem, ShMem, ShMemId, ShMemProvider},
3031
tuples::tuple_list,
@@ -112,7 +113,7 @@ pub fn main() {
112113
let mut executor = MyExecutor { shmem_id }.into_executor(tuple_list!(observer, bt_observer));
113114

114115
// Generator of printable bytearrays of max size 32
115-
let mut generator = RandPrintablesGenerator::new(32).unwrap();
116+
let mut generator = RandPrintablesGenerator::new(nonzero!(32));
116117

117118
// Generate 8 initial inputs
118119
state

fuzzers/baby/backtrace_baby_fuzzers/forkserver_executor/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use libafl_bolts::shmem::StdShMemProvider;
2121
#[cfg(target_vendor = "apple")]
2222
use libafl_bolts::shmem::UnixShMemProvider;
2323
use libafl_bolts::{
24+
nonzero,
2425
rands::StdRand,
2526
shmem::{ShMem, ShMemProvider},
2627
tuples::tuple_list,
@@ -97,7 +98,7 @@ pub fn main() {
9798
.unwrap();
9899

99100
// Generator of printable bytearrays of max size 32
100-
let mut generator = RandPrintablesGenerator::new(3).unwrap();
101+
let mut generator = RandPrintablesGenerator::new(nonzero!(32));
101102

102103
// Generate 8 initial inputs
103104
state

fuzzers/baby/backtrace_baby_fuzzers/rust_code_with_fork_executor/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use libafl::{
1919
state::StdState,
2020
};
2121
use libafl_bolts::{
22+
nonzero,
2223
ownedref::OwnedRefMut,
2324
rands::StdRand,
2425
shmem::{unix_shmem, ShMem, ShMemProvider},
@@ -122,7 +123,7 @@ pub fn main() {
122123
.expect("Failed to create the Executor");
123124

124125
// Generator of printable bytearrays of max size 32
125-
let mut generator = RandPrintablesGenerator::new(32).unwrap();
126+
let mut generator = RandPrintablesGenerator::new(nonzero!(32));
126127

127128
// Generate 8 initial inputs
128129
state

fuzzers/baby/backtrace_baby_fuzzers/rust_code_with_inprocess_executor/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use libafl::{
1818
stages::mutational::StdMutationalStage,
1919
state::StdState,
2020
};
21-
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice};
21+
use libafl_bolts::{nonzero, rands::StdRand, tuples::tuple_list, AsSlice};
2222

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

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

118118
// Generate 8 initial inputs
119119
state

fuzzers/forkserver/baby_fuzzer_with_forkexecutor/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use libafl::{
1818
state::StdState,
1919
};
2020
use libafl_bolts::{
21+
nonzero,
2122
rands::StdRand,
2223
shmem::{unix_shmem, ShMemProvider},
2324
tuples::tuple_list,
@@ -115,7 +116,7 @@ pub fn main() {
115116
.expect("Failed to create the Executor");
116117

117118
// Generator of printable bytearrays of max size 32
118-
let mut generator = RandPrintablesGenerator::new(32).unwrap();
119+
let mut generator = RandPrintablesGenerator::new(nonzero!(32));
119120

120121
// Generate 8 initial inputs
121122
state

fuzzers/forkserver/forkserver_libafl_cc/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ pub fn main() {
206206

207207
// Setup a mutational stage with a basic bytes mutator
208208
let mutator =
209-
StdScheduledMutator::with_max_stack_pow(havoc_mutations().merge(tokens_mutations()), 6)
210-
.unwrap();
209+
StdScheduledMutator::with_max_stack_pow(havoc_mutations().merge(tokens_mutations()), 6);
211210
let mut stages = tuple_list!(StdMutationalStage::new(mutator));
212211

213212
fuzzer

fuzzers/forkserver/forkserver_simple/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ pub fn main() {
202202

203203
// Setup a mutational stage with a basic bytes mutator
204204
let mutator =
205-
StdScheduledMutator::with_max_stack_pow(havoc_mutations().merge(tokens_mutations()), 6)
206-
.unwrap();
205+
StdScheduledMutator::with_max_stack_pow(havoc_mutations().merge(tokens_mutations()), 6);
207206
let mut stages = tuple_list!(StdMutationalStage::new(mutator));
208207

209208
fuzzer

fuzzers/fuzz_anything/baby_fuzzer_wasm/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use libafl::{
1515
state::{HasSolutions, StdState},
1616
Fuzzer, StdFuzzer,
1717
};
18-
use libafl_bolts::{rands::StdRand, serdeany::RegistryBuilder, tuples::tuple_list, AsSlice};
18+
use libafl_bolts::{
19+
nonzero, rands::StdRand, serdeany::RegistryBuilder, tuples::tuple_list, AsSlice,
20+
};
1921
use wasm_bindgen::prelude::*;
2022
use web_sys::{Performance, Window};
2123

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

128130
// Generator of printable bytearrays of max size 32
129-
let mut generator = RandPrintablesGenerator::new(32).unwrap();
131+
let mut generator = RandPrintablesGenerator::new(nonzero!(32));
130132

131133
// Generate 8 initial inputs
132134
state

fuzzers/fuzz_anything/baby_no_std/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use libafl::{
2525
stages::mutational::StdMutationalStage,
2626
state::StdState,
2727
};
28-
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice};
28+
use libafl_bolts::{nonzero, rands::StdRand, tuples::tuple_list, AsSlice};
2929
#[cfg(any(windows, unix))]
3030
use libc::{abort, printf};
3131
use static_alloc::Bump;
@@ -144,7 +144,7 @@ pub extern "C" fn main(_argc: isize, _argv: *const *const u8) -> isize {
144144
.expect("Failed to create the Executor");
145145

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

149149
// Generate 8 initial inputs
150150
state

fuzzers/fuzz_anything/libafl_atheris/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use libafl::{
3434
};
3535
use libafl_bolts::{
3636
core_affinity::Cores,
37+
nonzero,
3738
rands::StdRand,
3839
shmem::{ShMemProvider, StdShMemProvider},
3940
tuples::{tuple_list, Merge},
@@ -240,7 +241,7 @@ pub extern "C" fn LLVMFuzzerRunDriver(
240241
if state.must_load_initial_inputs() {
241242
if input_dirs.is_empty() {
242243
// Generator of printable bytearrays of max size 32
243-
let mut generator = RandBytesGenerator::new(32).unwrap();
244+
let mut generator = RandBytesGenerator::new(nonzero!(32));
244245

245246
// Generate 8 initial inputs
246247
state

fuzzers/fuzz_anything/push_harness/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use libafl::{
1818
stages::mutational::StdMutationalStage,
1919
state::StdState,
2020
};
21-
use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice};
21+
use libafl_bolts::{current_nanos, nonzero, rands::StdRand, tuples::tuple_list, AsSlice};
2222

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

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

9898
// Generate 8 initial inputs
9999
state

fuzzers/inprocess/fuzzbench_text/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,8 @@ fn fuzz_text(
602602
GrimoireRandomDeleteMutator::new(),
603603
),
604604
3,
605-
)
606-
.unwrap();
605+
);
606+
607607
let grimoire = StdMutationalStage::transforming(grimoire_mutator);
608608

609609
// A minimization+queue policy to get testcasess from the corpus

fuzzers/structure_aware/baby_fuzzer_custom_input/src/input.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use core::num::NonZeroUsize;
12
use std::{
23
borrow::Cow,
34
hash::{DefaultHasher, Hash, Hasher},
@@ -59,20 +60,20 @@ impl CustomInput {
5960
}
6061

6162
/// A generator for [`CustomInput`] used in this example
62-
pub struct CustomInputGenerator<S: HasRand> {
63-
pub bytes_generator: RandBytesGenerator<S>,
63+
pub struct CustomInputGenerator {
64+
pub bytes_generator: RandBytesGenerator,
6465
}
6566

66-
impl<S: HasRand> CustomInputGenerator<S> {
67+
impl CustomInputGenerator {
6768
/// Creates a new [`CustomInputGenerator`]
68-
pub fn new(max_len: usize) -> Result<Self, Error> {
69-
Ok(Self {
70-
bytes_generator: RandBytesGenerator::new(max_len)?,
71-
})
69+
pub fn new(max_len: NonZeroUsize) -> Self {
70+
Self {
71+
bytes_generator: RandBytesGenerator::new(max_len),
72+
}
7273
}
7374
}
7475

75-
impl<S> Generator<CustomInput, S> for CustomInputGenerator<S>
76+
impl<S> Generator<CustomInput, S> for CustomInputGenerator
7677
where
7778
S: HasRand,
7879
{
@@ -99,15 +100,12 @@ pub struct ToggleOptionalByteArrayMutator<G> {
99100
generator: G,
100101
}
101102

102-
impl<S> ToggleOptionalByteArrayMutator<RandBytesGenerator<S>>
103-
where
104-
S: HasRand,
105-
{
103+
impl ToggleOptionalByteArrayMutator<RandBytesGenerator> {
106104
/// Creates a new [`ToggleOptionalByteArrayMutator`]
107-
pub fn new(length: usize) -> Result<Self, Error> {
108-
Ok(Self {
109-
generator: RandBytesGenerator::new(length)?,
110-
})
105+
pub fn new(length: NonZeroUsize) -> Self {
106+
Self {
107+
generator: RandBytesGenerator::new(length),
108+
}
111109
}
112110
}
113111

0 commit comments

Comments
 (0)