Skip to content

Commit 70e2116

Browse files
Fix clippy warnings and TODOs in binary_only fuzzers (#3564)
* feat: fix clippy warnings in frida_executable_libpng * feat: fix clippy warnings in frida_libpng * feat: fix clippy warnings in fuzzbench_fork_qemu * feat: fix clippy warnings in fuzzbench_qemu * feat: address the TODOs present in intel_pt_baby_fuzzer * feat: address the TODOs present in intel_pt_command_executor * feat: fix clippy warnings for qemu_cmin * feat: fix clippy warnings in qemu_launcher * feat: run cargo +nightly fmt on all fuzzers in binary_only * feat: switch out StdMapObserver for ConstMapObserver in fuzzers/binary_only/intel_pt_* * fix: run cargo +nightly fmt on fuzzers/binary_only/intel_pt_*
1 parent 35b9b1e commit 70e2116

File tree

9 files changed

+28
-21
lines changed

9 files changed

+28
-21
lines changed

fuzzers/binary_only/frida_executable_libpng/src/fuzzer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ unsafe fn fuzz(
252252
let coverage = CoverageRuntime::new();
253253
let cmplog = CmpLogRuntime::new();
254254

255-
let mut frida_helper = Rc::new(RefCell::new(FridaInstrumentationHelper::new(
255+
let frida_helper = Rc::new(RefCell::new(FridaInstrumentationHelper::new(
256256
&gum,
257257
options,
258258
tuple_list!(coverage, cmplog),
@@ -397,7 +397,7 @@ unsafe fn fuzz(
397397

398398
let coverage = CoverageRuntime::new();
399399

400-
let mut frida_helper = Rc::new(RefCell::new(FridaInstrumentationHelper::new(
400+
let frida_helper = Rc::new(RefCell::new(FridaInstrumentationHelper::new(
401401
&gum,
402402
options,
403403
tuple_list!(coverage),

fuzzers/binary_only/frida_executable_libpng/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![allow(clippy::missing_safety_doc)]
21
use std::mem::transmute;
32

43
use libc::{c_void, dlsym, RTLD_NEXT};
@@ -23,6 +22,8 @@ extern "C" fn _dummy_main(_argc: i32, _argv: *const *const u8, _env: *const *con
2322

2423
static mut ORIG_MAIN: MainFunc = _dummy_main;
2524

25+
/// # Safety
26+
/// Accesses mutable static variable
2627
#[no_mangle]
2728
pub unsafe extern "C" fn main_hook(
2829
_argc: i32,
@@ -33,6 +34,8 @@ pub unsafe extern "C" fn main_hook(
3334
0
3435
}
3536

37+
/// # Safety
38+
/// Modifies mutable static variable, performs unsafe memory transmutation
3639
#[no_mangle]
3740
pub unsafe extern "C" fn __libc_start_main(
3841
main: extern "C" fn(i32, *const *const u8, *const *const u8) -> i32,

fuzzers/binary_only/frida_libpng/src/fuzzer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ fn fuzz(options: &FuzzerOptions) -> Result<(), Error> {
244244

245245
let mut stages = tuple_list!(
246246
IfElseStage::new(
247-
|_, _, _, _| Ok(is_cmplog(&options, &client_description)),
247+
|_, _, _, _| Ok(is_cmplog(options, &client_description)),
248248
tuple_list!(tracing, i2s),
249249
tuple_list!()
250250
),

fuzzers/binary_only/fuzzbench_fork_qemu/src/fuzzer.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,12 @@ fn fuzz(
400400

401401
if state.must_load_initial_inputs() {
402402
state
403-
.load_initial_inputs(&mut fuzzer, &mut executor, &mut mgr, &[seed_dir.clone()])
403+
.load_initial_inputs(
404+
&mut fuzzer,
405+
&mut executor,
406+
&mut mgr,
407+
std::slice::from_ref(&seed_dir),
408+
)
404409
.unwrap_or_else(|_| {
405410
println!("Failed to load initial corpus at {:?}", &seed_dir);
406411
process::exit(0);

fuzzers/binary_only/fuzzbench_qemu/src/fuzzer.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,12 @@ fn fuzz(
413413

414414
if state.must_load_initial_inputs() {
415415
state
416-
.load_initial_inputs(&mut fuzzer, &mut executor, &mut mgr, &[seed_dir.clone()])
416+
.load_initial_inputs(
417+
&mut fuzzer,
418+
&mut executor,
419+
&mut mgr,
420+
std::slice::from_ref(&seed_dir),
421+
)
417422
.unwrap_or_else(|_| {
418423
println!("Failed to load initial corpus at {:?}", &seed_dir);
419424
process::exit(0);

fuzzers/binary_only/intel_pt_baby_fuzzer/src/main.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,18 @@ use libafl::{
1717
generators::RandPrintablesGenerator,
1818
inputs::{BytesInput, HasTargetBytes},
1919
mutators::{havoc_mutations::havoc_mutations, scheduled::HavocScheduledMutator},
20-
observers::StdMapObserver,
20+
observers::ConstMapObserver,
2121
schedulers::QueueScheduler,
2222
stages::mutational::StdMutationalStage,
2323
state::StdState,
2424
};
25-
use libafl_bolts::{current_nanos, rands::StdRand, tuples::tuple_list, AsSlice};
25+
use libafl_bolts::{current_nanos, nonnull_raw_mut, rands::StdRand, tuples::tuple_list, AsSlice};
2626
use proc_maps::get_process_maps;
2727

2828
// Coverage map
2929
const MAP_SIZE: usize = 4096;
3030
static mut MAP: [u8; MAP_SIZE] = [0; MAP_SIZE];
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 MAP_PTR: *mut u8 = unsafe { MAP.as_mut_ptr() };
31+
static mut MAP_PTR: *mut u8 = &raw mut MAP as _;
3432

3533
pub fn main() {
3634
// The closure that we want to fuzz
@@ -50,7 +48,7 @@ pub fn main() {
5048
};
5149

5250
// Create an observation channel using the map
53-
let observer = unsafe { StdMapObserver::from_mut_ptr("signals", MAP_PTR, MAP_SIZE) };
51+
let observer = unsafe { ConstMapObserver::from_mut_ptr("signals", nonnull_raw_mut!(MAP)) };
5452

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

fuzzers/binary_only/intel_pt_command_executor/src/main.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,19 @@ use libafl::{
1414
generators::RandPrintablesGenerator,
1515
monitors::SimpleMonitor,
1616
mutators::{havoc_mutations::havoc_mutations, scheduled::HavocScheduledMutator},
17-
observers::StdMapObserver,
17+
observers::ConstMapObserver,
1818
schedulers::QueueScheduler,
1919
stages::mutational::StdMutationalStage,
2020
state::StdState,
2121
};
22-
use libafl_bolts::{core_affinity, rands::StdRand, tuples::tuple_list, Error};
22+
use libafl_bolts::{core_affinity, nonnull_raw_mut, rands::StdRand, tuples::tuple_list, Error};
2323
use libafl_intelpt::{AddrFilter, AddrFilterType, AddrFilters, IntelPT, PAGE_SIZE};
2424
use object::{elf::PF_X, Object, ObjectSegment, SegmentFlags};
2525

2626
// Coverage map
2727
const MAP_SIZE: usize = 4096;
2828
static mut MAP: [u8; MAP_SIZE] = [0; MAP_SIZE];
29-
// TODO: This will break soon, fix me! See https://github.com/AFLplusplus/LibAFL/issues/2786
30-
#[allow(static_mut_refs)] // only a problem in nightly
31-
static mut MAP_PTR: *mut u8 = unsafe { MAP.as_mut_ptr() };
29+
static mut MAP_PTR: *mut u8 = &raw mut MAP as _;
3230

3331
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
3432
// Let's set the default logging level to `warn`
@@ -70,7 +68,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
7068
log::debug!("Using core {} for fuzzing", cpu.0);
7169

7270
// Create an observation channel using the map
73-
let observer = unsafe { StdMapObserver::from_mut_ptr("signals", MAP_PTR, MAP_SIZE) };
71+
let observer = unsafe { ConstMapObserver::from_mut_ptr("signals", nonnull_raw_mut!(MAP)) };
7472

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

fuzzers/binary_only/qemu_cmin/src/fuzzer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pub fn fuzz() -> Result<(), Error> {
144144
let stdout_callback = |buf: &[u8]| {
145145
if let Ok(s) = from_utf8(buf) {
146146
let msg = s.trim_end();
147-
if msg.len() != 0 {
147+
if !msg.is_empty() {
148148
log::info!("{msg}");
149149
}
150150
}

fuzzers/binary_only/qemu_launcher/src/harness.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ pub const MAX_INPUT_SIZE: usize = 1_048_576; // 1MB
1919
impl Harness {
2020
/// Change environment
2121
#[inline]
22-
#[expect(clippy::ptr_arg)]
2322
pub fn edit_env(_env: &mut Vec<(String, String)>) {}
2423

2524
/// Change arguments
2625
#[inline]
27-
#[expect(clippy::ptr_arg)]
2826
pub fn edit_args(_args: &mut Vec<String>) {}
2927

3028
/// Helper function to find the function we want to fuzz.

0 commit comments

Comments
 (0)