From ad85b7fbce6e62ac223ef4119f8eb8c939cbdecc Mon Sep 17 00:00:00 2001 From: mzfr Date: Tue, 17 Dec 2024 14:02:04 +0800 Subject: [PATCH] Switched from StdMapObserve to ConstMapObserver to create observer Also updated signals_set to directly modify SIGNALS array --- fuzzers/fuzz_anything/baby_no_std/src/main.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/fuzzers/fuzz_anything/baby_no_std/src/main.rs b/fuzzers/fuzz_anything/baby_no_std/src/main.rs index 80fde8fdfa..6567720ada 100644 --- a/fuzzers/fuzz_anything/baby_no_std/src/main.rs +++ b/fuzzers/fuzz_anything/baby_no_std/src/main.rs @@ -8,7 +8,6 @@ extern crate alloc; use alloc::ffi::CString; #[cfg(not(any(windows)))] use core::panic::PanicInfo; -use core::ptr::write; use libafl::{ corpus::InMemoryCorpus, @@ -20,12 +19,12 @@ use libafl::{ inputs::{BytesInput, HasTargetBytes}, monitors::SimpleMonitor, mutators::{havoc_mutations::havoc_mutations, scheduled::StdScheduledMutator}, - observers::StdMapObserver, + observers::ConstMapObserver, schedulers::QueueScheduler, stages::mutational::StdMutationalStage, 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))] use libc::{abort, printf}; use static_alloc::Bump; @@ -48,12 +47,10 @@ fn panic(_info: &PanicInfo) -> ! { /// Coverage map with explicit assignments due to the lack of instrumentation static mut SIGNALS: [u8; 16] = [0; 16]; -#[allow(static_mut_refs)] -static mut SIGNALS_PTR: *mut u8 = unsafe { SIGNALS.as_mut_ptr() }; /// Assign a signal to the signals map fn signals_set(idx: usize) { - unsafe { write(SIGNALS_PTR.add(idx), 1) }; + unsafe { SIGNALS[idx] = 1 }; } /// Provide custom time in `no_std` environment @@ -89,9 +86,7 @@ pub extern "C" fn main(_argc: isize, _argv: *const *const u8) -> isize { }; // Create an observation channel using the signals map - #[allow(static_mut_refs)] - 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 let mut feedback = MaxMapFeedback::new(&observer);