Skip to content

Commit

Permalink
Switched from StdMapObserve to ConstMapObserver to create observer
Browse files Browse the repository at this point in the history
Also updated signals_set to directly modify SIGNALS array
  • Loading branch information
mzfr committed Dec 17, 2024
1 parent 3175857 commit ad85b7f
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions fuzzers/fuzz_anything/baby_no_std/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit ad85b7f

Please sign in to comment.