Cleanup clippy warnings in example fuzzers (#2770)

* cleanup warnings in fuzz_anything

* Refactor: Removed MatchNameRef from tuple import

* Used addr_of! macro instead of taking direct reference

* Remove unecessary unsafe block when getting references to SIGNALS array

* Switched from StdMapObserve to ConstMapObserver to create observer

Also updated signals_set to directly modify SIGNALS array

* Format code using fmt_all.sh
This commit is contained in:
Mehtab Zafar 2024-12-19 15:33:13 +08:00 committed by GitHub
parent 57cecca927
commit 358a5ea7f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 9 additions and 12 deletions

View File

@ -21,7 +21,7 @@ use libafl::{
use libafl_bolts::{ use libafl_bolts::{
rands::StdRand, rands::StdRand,
shmem::{ShMem, ShMemProvider, UnixShMemProvider}, shmem::{ShMem, ShMemProvider, UnixShMemProvider},
tuples::{tuple_list, Handled, MatchNameRef, Merge}, tuples::{tuple_list, Handled, Merge},
AsSliceMut, Truncate, AsSliceMut, Truncate,
}; };
use libafl_targets::EDGES_MAP_DEFAULT_SIZE; use libafl_targets::EDGES_MAP_DEFAULT_SIZE;

View File

@ -8,7 +8,6 @@ extern crate alloc;
use alloc::ffi::CString; use alloc::ffi::CString;
#[cfg(not(any(windows)))] #[cfg(not(any(windows)))]
use core::panic::PanicInfo; use core::panic::PanicInfo;
use core::ptr::write;
use libafl::{ use libafl::{
corpus::InMemoryCorpus, corpus::InMemoryCorpus,
@ -20,12 +19,12 @@ use libafl::{
inputs::{BytesInput, HasTargetBytes}, inputs::{BytesInput, HasTargetBytes},
monitors::SimpleMonitor, monitors::SimpleMonitor,
mutators::{havoc_mutations::havoc_mutations, scheduled::StdScheduledMutator}, mutators::{havoc_mutations::havoc_mutations, scheduled::StdScheduledMutator},
observers::StdMapObserver, observers::ConstMapObserver,
schedulers::QueueScheduler, schedulers::QueueScheduler,
stages::mutational::StdMutationalStage, stages::mutational::StdMutationalStage,
state::StdState, state::StdState,
}; };
use libafl_bolts::{nonzero, rands::StdRand, tuples::tuple_list, AsSlice}; use libafl_bolts::{nonnull_raw_mut, nonzero, rands::StdRand, tuples::tuple_list, AsSlice};
#[cfg(any(windows, unix))] #[cfg(any(windows, unix))]
use libc::{abort, printf}; use libc::{abort, printf};
use static_alloc::Bump; use static_alloc::Bump;
@ -48,11 +47,10 @@ fn panic(_info: &PanicInfo) -> ! {
/// Coverage map with explicit assignments due to the lack of instrumentation /// Coverage map with explicit assignments due to the lack of instrumentation
static mut SIGNALS: [u8; 16] = [0; 16]; static mut SIGNALS: [u8; 16] = [0; 16];
static mut SIGNALS_PTR: *mut u8 = unsafe { SIGNALS.as_mut_ptr() };
/// Assign a signal to the signals map /// Assign a signal to the signals map
fn signals_set(idx: usize) { fn signals_set(idx: usize) {
unsafe { write(SIGNALS_PTR.add(idx), 1) }; unsafe { SIGNALS[idx] = 1 };
} }
/// Provide custom time in `no_std` environment /// Provide custom time in `no_std` environment
@ -88,8 +86,7 @@ pub extern "C" fn main(_argc: isize, _argv: *const *const u8) -> isize {
}; };
// Create an observation channel using the signals map // Create an observation channel using the signals map
let observer = unsafe { StdMapObserver::from_mut_ptr("signals", SIGNALS_PTR, SIGNALS.len()) }; let observer = unsafe { ConstMapObserver::from_mut_ptr("signals", nonnull_raw_mut!(SIGNALS)) };
// Feedback to rate the interestingness of an input // Feedback to rate the interestingness of an input
let mut feedback = MaxMapFeedback::new(&observer); let mut feedback = MaxMapFeedback::new(&observer);

View File

@ -39,7 +39,7 @@ fn input_generator() {
ExitKind::Ok ExitKind::Ok
}; };
let signals_ptr = unsafe { &raw mut SIGNALS }; let signals_ptr = &raw mut SIGNALS;
let signals_len = unsafe { *signals_ptr }.len(); let signals_len = unsafe { *signals_ptr }.len();
// Create an observation channel using the signals map // Create an observation channel using the signals map

View File

@ -2,7 +2,7 @@
//! The example harness is built for libpng. //! The example harness is built for libpng.
//! In this example, you will see the use of the `launcher` feature. //! In this example, you will see the use of the `launcher` feature.
//! The `launcher` will spawn new processes for each cpu core. //! The `launcher` will spawn new processes for each cpu core.
use core::time::Duration; use core::{ptr::addr_of, time::Duration};
use std::{env, net::SocketAddr, path::PathBuf}; use std::{env, net::SocketAddr, path::PathBuf};
use clap::Parser; use clap::Parser;
@ -200,7 +200,7 @@ pub extern "C" fn libafl_main() {
&edges_observer, &edges_observer,
&mut state, &mut state,
QueueScheduler::new(), QueueScheduler::new(),
unsafe { &ACCOUNTING_MEMOP_MAP }, unsafe { &*addr_of!(ACCOUNTING_MEMOP_MAP) },
); );
// A fuzzer with feedbacks and a corpus scheduler // A fuzzer with feedbacks and a corpus scheduler

View File

@ -29,7 +29,7 @@ use libafl_bolts::{rands::StdRand, tuples::tuple_list};
/// Coverage map with explicit assignments due to the lack of instrumentation /// Coverage map with explicit assignments due to the lack of instrumentation
const SIGNALS_LEN: usize = 16; const SIGNALS_LEN: usize = 16;
static mut SIGNALS: [u8; SIGNALS_LEN] = [0; SIGNALS_LEN]; static mut SIGNALS: [u8; SIGNALS_LEN] = [0; SIGNALS_LEN];
static mut SIGNALS_PTR: *mut u8 = unsafe { &raw mut SIGNALS as _ }; static mut SIGNALS_PTR: *mut u8 = &raw mut SIGNALS as _;
/* /*
/// Assign a signal to the signals map /// Assign a signal to the signals map
fn signals_set(idx: usize) { fn signals_set(idx: usize) {