Skip to content

Commit a812faa

Browse files
Clean up TODOs in baby_fuzzers (#3547)
* feat: fix baby_fuzzer fuzzer examples where warnings were present * fix: fix clippy warning regarding empty line after doc comment * fix: fix taplo linting error on a config.toml * feat: change some StdMapObservers to ConstMapObservers * fix: add TODOs to fix this file later
1 parent 7b0dc63 commit a812faa

File tree

8 files changed

+36
-45
lines changed

8 files changed

+36
-45
lines changed

fuzzers/baby/baby_fuzzer/src/main.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@ use libafl::{
1515
generators::RandPrintablesGenerator,
1616
inputs::{BytesInput, HasTargetBytes},
1717
mutators::{havoc_mutations::havoc_mutations, scheduled::HavocScheduledMutator},
18-
observers::StdMapObserver,
18+
observers::ConstMapObserver,
1919
schedulers::QueueScheduler,
2020
stages::mutational::StdMutationalStage,
2121
state::StdState,
2222
};
23-
use libafl_bolts::{current_nanos, nonzero, rands::StdRand, tuples::tuple_list, AsSlice};
23+
use libafl_bolts::{
24+
current_nanos, nonnull_raw_mut, nonzero, rands::StdRand, tuples::tuple_list, AsSlice,
25+
};
2426

2527
/// Coverage map with explicit assignments due to the lack of instrumentation
26-
static mut SIGNALS: [u8; 16] = [0; 16];
27-
// TODO: This will break soon, fix me! See https://github.com/AFLplusplus/LibAFL/issues/2786
28-
#[allow(static_mut_refs)] // only a problem in nightly
29-
static mut SIGNALS_PTR: *mut u8 = unsafe { SIGNALS.as_mut_ptr() };
28+
const SIGNALS_LEN: usize = 16;
29+
static mut SIGNALS: [u8; SIGNALS_LEN] = [0; SIGNALS_LEN];
30+
static mut SIGNALS_PTR: *mut u8 = &raw mut SIGNALS as _;
3031

3132
/// Assign a signal to the signals map
3233
fn signals_set(idx: usize) {
@@ -64,9 +65,7 @@ pub fn main() {
6465
};
6566

6667
// Create an observation channel using the signals map
67-
// TODO: This will break soon, fix me! See https://github.com/AFLplusplus/LibAFL/issues/2786
68-
#[allow(static_mut_refs)] // only a problem in nightly
69-
let observer = unsafe { StdMapObserver::from_mut_ptr("signals", SIGNALS_PTR, SIGNALS.len()) };
68+
let observer = unsafe { ConstMapObserver::from_mut_ptr("signals", nonnull_raw_mut!(SIGNALS)) };
7069

7170
// Feedback to rate the interestingness of an input
7271
let mut feedback = MaxMapFeedback::new(&observer);

fuzzers/baby/baby_fuzzer_custom_executor/src/main.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ use libafl::{
1616
generators::RandPrintablesGenerator,
1717
inputs::HasTargetBytes,
1818
mutators::{havoc_mutations::havoc_mutations, scheduled::HavocScheduledMutator},
19-
observers::StdMapObserver,
19+
observers::ConstMapObserver,
2020
schedulers::QueueScheduler,
2121
stages::{mutational::StdMutationalStage, AflStatsStage, CalibrationStage},
2222
state::{HasCorpus, HasExecutions, StdState},
2323
};
24-
use libafl_bolts::{current_nanos, nonzero, rands::StdRand, tuples::tuple_list, AsSlice};
24+
use libafl_bolts::{
25+
current_nanos, nonnull_raw_mut, nonzero, rands::StdRand, tuples::tuple_list, AsSlice,
26+
};
2527
/// Coverage map with explicit assignments due to the lack of instrumentation
26-
static mut SIGNALS: [u8; 16] = [0; 16];
28+
const SIGNALS_LEN: usize = 16;
29+
static mut SIGNALS: [u8; SIGNALS_LEN] = [0; SIGNALS_LEN];
2730
static mut SIGNALS_PTR: *mut u8 = &raw mut SIGNALS as _;
28-
// TODO: This will break soon, fix me! See https://github.com/AFLplusplus/LibAFL/issues/2786
29-
#[allow(static_mut_refs)] // only a problem in nightly
30-
static SIGNALS_LEN: usize = unsafe { SIGNALS.len() };
3131

3232
/// Assign a signal to the signals map
3333
fn signals_set(idx: usize) {
@@ -79,7 +79,7 @@ where
7979

8080
pub fn main() {
8181
// Create an observation channel using the signals map
82-
let observer = unsafe { StdMapObserver::from_mut_ptr("signals", SIGNALS_PTR, SIGNALS_LEN) };
82+
let observer = unsafe { ConstMapObserver::from_mut_ptr("signals", nonnull_raw_mut!(SIGNALS)) };
8383

8484
// Feedback to rate the interestingness of an input
8585
let mut feedback = MaxMapFeedback::new(&observer);

fuzzers/baby/baby_fuzzer_minimizing/src/main.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ use libafl::prelude::*;
66
use libafl_bolts::prelude::*;
77

88
/// Coverage map with explicit assignments due to the lack of instrumentation
9-
static mut SIGNALS: [u8; 16] = [0; 16];
10-
// TODO: This will break soon, fix me! See https://github.com/AFLplusplus/LibAFL/issues/2786
11-
#[allow(static_mut_refs)] // only a problem in nightly
12-
static mut SIGNALS_PTR: *mut u8 = unsafe { SIGNALS.as_mut_ptr() };
9+
const SIGNALS_LEN: usize = 16;
10+
static mut SIGNALS: [u8; SIGNALS_LEN] = [0; SIGNALS_LEN];
11+
static mut SIGNALS_PTR: *mut u8 = &raw mut SIGNALS as _;
1312

1413
/// Assign a signal to the signals map
1514
fn signals_set(idx: usize) {
@@ -35,9 +34,7 @@ pub fn main() -> Result<(), Error> {
3534
};
3635

3736
// Create an observation channel using the signals map
38-
// TODO: This will break soon, fix me! See https://github.com/AFLplusplus/LibAFL/issues/2786
39-
#[allow(static_mut_refs)] // only a problem in nightly
40-
let observer = unsafe { StdMapObserver::from_mut_ptr("signals", SIGNALS_PTR, SIGNALS.len()) };
37+
let observer = unsafe { ConstMapObserver::from_mut_ptr("signals", nonnull_raw_mut!(SIGNALS)) };
4138

4239
let factory = ObserverEqualityFactory::new(&observer);
4340

fuzzers/baby/baby_fuzzer_swap_differential/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ pub fn main() {
108108
};
109109

110110
// create the base maps used to observe the different executors from two independent maps
111+
// TODO: Replace with ConstMapObserver
111112
let mut first_map_observer =
112113
unsafe { StdMapObserver::from_mut_ptr("first-edges", first_edges.0, first_edges.1) };
113114
let mut second_map_observer =
@@ -143,11 +144,10 @@ pub fn main() {
143144
EDGES = core::slice::from_raw_parts_mut(alloc_zeroed(layout), num_edges * 2);
144145
}
145146

146-
// TODO: This will break soon, fix me! See https://github.com/AFLplusplus/LibAFL/issues/2786
147-
#[allow(static_mut_refs)] // only a problem on nightly
148-
let edges_ptr = unsafe { EDGES.as_mut_ptr() };
147+
let edges_ptr: *mut u8 = &raw mut EDGES as _;
149148

150149
// create the base maps used to observe the different executors by splitting a slice
150+
// TODO: Replace with ConstMapObserver
151151
let mut first_map_observer =
152152
unsafe { StdMapObserver::from_mut_ptr("first-edges", edges_ptr, num_edges) };
153153
let mut second_map_observer = unsafe {

fuzzers/baby/baby_fuzzer_unicode/src/main.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,18 @@ use libafl::{
1717
HavocScheduledMutator, UnicodeCategoryRandMutator, UnicodeInput,
1818
UnicodeSubcategoryRandMutator,
1919
},
20-
observers::StdMapObserver,
20+
observers::ConstMapObserver,
2121
schedulers::QueueScheduler,
2222
stages::{mutational::StdMutationalStage, UnicodeIdentificationStage},
2323
state::StdState,
2424
Evaluator,
2525
};
26-
use libafl_bolts::{rands::StdRand, tuples::tuple_list, AsSlice};
26+
use libafl_bolts::{nonnull_raw_mut, rands::StdRand, tuples::tuple_list, AsSlice};
2727

2828
/// Coverage map with explicit assignments due to the lack of instrumentation
29-
static mut SIGNALS: [u8; 64] = [0; 64];
30-
static mut SIGNALS_PTR: *mut u8 = (&raw mut SIGNALS).cast();
31-
// TODO: This will break soon, fix me! See https://github.com/AFLplusplus/LibAFL/issues/2786
32-
#[allow(static_mut_refs)] // only a problem in nightly
33-
static mut SIGNALS_LEN: usize = unsafe { SIGNALS.len() };
29+
const SIGNALS_LEN: usize = 64;
30+
static mut SIGNALS: [u8; SIGNALS_LEN] = [0; SIGNALS_LEN];
31+
static mut SIGNALS_PTR: *mut u8 = &raw mut SIGNALS as _;
3432

3533
/// Assign a signal to the signals map
3634
fn signals_set(idx: usize) {
@@ -62,7 +60,7 @@ pub fn main() {
6260
};
6361

6462
// Create an observation channel using the signals map
65-
let observer = unsafe { StdMapObserver::from_mut_ptr("signals", SIGNALS_PTR, SIGNALS_LEN) };
63+
let observer = unsafe { ConstMapObserver::from_mut_ptr("signals", nonnull_raw_mut!(SIGNALS)) };
6664

6765
// Feedback to rate the interestingness of an input
6866
let mut feedback = MaxMapFeedback::new(&observer);

fuzzers/baby/backtrace_baby_fuzzers/rust_code_with_inprocess_executor/.cargo/config

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
rustflags = ["-Cforce-unwind-tables=y"]

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,17 @@ use libafl::{
1313
inputs::{BytesInput, HasTargetBytes},
1414
monitors::SimpleMonitor,
1515
mutators::{havoc_mutations::havoc_mutations, scheduled::HavocScheduledMutator},
16-
observers::{BacktraceObserver, StdMapObserver},
16+
observers::{BacktraceObserver, ConstMapObserver},
1717
schedulers::QueueScheduler,
1818
stages::mutational::StdMutationalStage,
1919
state::StdState,
2020
};
21-
use libafl_bolts::{nonzero, rands::StdRand, tuples::tuple_list, AsSlice};
21+
use libafl_bolts::{nonnull_raw_mut, nonzero, rands::StdRand, tuples::tuple_list, AsSlice};
2222

2323
/// Coverage map with explicit assignments due to the lack of instrumentation
24-
static mut SIGNALS: [u8; 16] = [0; 16];
25-
// TODO: This will break soon, fix me! See https://github.com/AFLplusplus/LibAFL/issues/2786
26-
#[allow(static_mut_refs)] // only a problem in nightly
27-
static mut SIGNALS_PTR: *mut u8 = unsafe { SIGNALS.as_mut_ptr() };
24+
const SIGNALS_LEN: usize = 16;
25+
static mut SIGNALS: [u8; SIGNALS_LEN] = [0; SIGNALS_LEN];
26+
static mut SIGNALS_PTR: *mut u8 = &raw mut SIGNALS as _;
2827

2928
/// Assign a signal to the signals map
3029
fn signals_set(idx: usize) {
@@ -60,9 +59,7 @@ pub fn main() {
6059
};
6160

6261
// Create an observation channel using the signals map
63-
// TODO: This will break soon, fix me! See https://github.com/AFLplusplus/LibAFL/issues/2786
64-
#[allow(static_mut_refs)] // only a problem in nightly
65-
let observer = unsafe { StdMapObserver::from_mut_ptr("signals", SIGNALS_PTR, SIGNALS.len()) };
62+
let observer = unsafe { ConstMapObserver::from_mut_ptr("signals", nonnull_raw_mut!(SIGNALS)) };
6663
// Create a stacktrace observer to add the observers tuple
6764
let bt_observer = BacktraceObserver::owned(
6865
"BacktraceObserver",

0 commit comments

Comments
 (0)