diff --git a/afl/src/events/llmp.rs b/afl/src/events/llmp.rs index 677ced499f..c38d222a50 100644 --- a/afl/src/events/llmp.rs +++ b/afl/src/events/llmp.rs @@ -55,6 +55,8 @@ use core::{ sync::atomic::{compiler_fence, Ordering}, time::Duration, }; + +#[cfg(feature = "std")] use std::{ io::{Read, Write}, net::{TcpListener, TcpStream}, @@ -64,6 +66,7 @@ use std::{ use crate::utils::next_pow2; use crate::AflError; +#[cfg(feature = "std")] use super::shmem_translated::AflShmem; /// We'll start off with 256 megabyte maps per fuzzer client diff --git a/afl/src/events/mod.rs b/afl/src/events/mod.rs index 5601bdebce..7a6a0d4c5d 100644 --- a/afl/src/events/mod.rs +++ b/afl/src/events/mod.rs @@ -1,31 +1,29 @@ +// TODO: llmp can be no_std, if we abstract away page creation #[cfg(feature = "std")] pub mod llmp; #[cfg(feature = "std")] pub mod shmem_translated; -use alloc::string::String; +use alloc::string::{String, ToString}; +use alloc::vec::Vec; +use core::time::Duration; use core::{marker::PhantomData, time}; - +#[cfg(feature = "std")] use serde::{Deserialize, Serialize}; -//#[cfg(feature = "std")] -//pub mod shmem_translated; - #[cfg(feature = "std")] -use std::time::Duration; - +use self::llmp::Tag; use crate::corpus::Corpus; use crate::executors::Executor; use crate::feedbacks::FeedbacksTuple; use crate::inputs::Input; use crate::observers::ObserversTuple; +#[cfg(feature = "std")] use crate::serde_anymap::Ptr; use crate::utils::Rand; use crate::AflError; use crate::{engines::State, utils}; -use self::llmp::Tag; - #[derive(Debug, Copy, Clone)] /// Indicate if an event worked or not pub enum BrokerEventResult { @@ -377,6 +375,8 @@ where message, phantom: _, } => { + let (_, _) = (message, severity_level); + #[cfg(feature = "std")] println!("[LOG {}]: {}", severity_level, message); Ok(BrokerEventResult::Handled) } //_ => Ok(BrokerEventResult::Forward), @@ -725,6 +725,7 @@ where phantom: PhantomData<(C, E, OT, FT, I, R)>, } +#[cfg(feature = "std")] impl LlmpEventManager where C: Corpus, diff --git a/afl/src/feedbacks/mod.rs b/afl/src/feedbacks/mod.rs index 8206a73f5d..9500dc4848 100644 --- a/afl/src/feedbacks/mod.rs +++ b/afl/src/feedbacks/mod.rs @@ -1,3 +1,4 @@ +use alloc::string::{String, ToString}; use alloc::vec::Vec; use core::marker::PhantomData; use num::Integer; @@ -254,7 +255,7 @@ where pub fn with_history_map(name: &'static str, history_map: Vec) -> Self { Self { history_map: history_map, - name: name.into(), + name: name.to_string(), phantom: PhantomData, } } diff --git a/afl/src/observers/mod.rs b/afl/src/observers/mod.rs index c57643dc0f..545f1373c7 100644 --- a/afl/src/observers/mod.rs +++ b/afl/src/observers/mod.rs @@ -1,8 +1,10 @@ extern crate num; +use alloc::string::{String, ToString}; +use alloc::vec::Vec; use serde::{Deserialize, Serialize}; -use crate::serde_anymap::{Cptr, ArrayMut}; +use crate::serde_anymap::{ArrayMut, Cptr}; use crate::tuples::{MatchNameAndType, MatchType, Named, TupleList}; use crate::AflError; @@ -192,7 +194,7 @@ where let initial = if map.len() > 0 { map[0] } else { T::default() }; Self { map: ArrayMut::Cptr((map.as_mut_ptr(), map.len())), - name: name.into(), + name: name.to_string(), initial, } } @@ -203,7 +205,7 @@ where let initial = if len > 0 { *map_ptr } else { T::default() }; StdMapObserver { map: ArrayMut::Cptr((map_ptr, len)), - name: name.into(), + name: name.to_string(), initial, } } @@ -255,7 +257,7 @@ where fn map_mut(&mut self) -> &mut [T] { self.map.as_mut_slice() } - + #[inline] fn usable_count(&self) -> usize { *self.size.as_ref() @@ -293,7 +295,12 @@ where } /// Creates a new MapObserver from a raw pointer - pub fn new_from_ptr(name: &'static str, map_ptr: *mut T, max_len: usize, size_ptr: *const usize) -> Self { + pub fn new_from_ptr( + name: &'static str, + map_ptr: *mut T, + max_len: usize, + size_ptr: *const usize, + ) -> Self { unsafe { let initial = if max_len > 0 { *map_ptr } else { T::default() }; VariableMapObserver { diff --git a/afl/src/utils.rs b/afl/src/utils.rs index 08f188ca25..bff255e56f 100644 --- a/afl/src/utils.rs +++ b/afl/src/utils.rs @@ -84,8 +84,10 @@ pub fn current_time() -> time::Duration { /// Current time (fixed fallback for no_std) #[cfg(not(feature = "std"))] #[inline] -fn current_time() -> time::Duration { - self.start_time() +pub fn current_time() -> time::Duration { + // We may not have a rt clock available. + // TODO: Make it somehow plugin-able + time::Duration::from_millis(1) } #[cfg(feature = "std")] diff --git a/fuzzers/libfuzzer/src/lib.rs b/fuzzers/libfuzzer/src/lib.rs index eee459df65..38a985038e 100644 --- a/fuzzers/libfuzzer/src/lib.rs +++ b/fuzzers/libfuzzer/src/lib.rs @@ -7,7 +7,7 @@ use afl::engines::Engine; use afl::engines::Fuzzer; use afl::engines::State; use afl::engines::StdFuzzer; -use afl::events::{SimpleStats, LlmpEventManager}; +use afl::events::{LlmpEventManager, SimpleStats}; use afl::executors::inmemory::InMemoryExecutor; use afl::executors::{Executor, ExitKind}; use afl::feedbacks::MaxMapFeedback; diff --git a/fuzzers/qemufuzzer/src/lib.rs b/fuzzers/qemufuzzer/src/lib.rs index 7454f25d3b..c18010f11e 100644 --- a/fuzzers/qemufuzzer/src/lib.rs +++ b/fuzzers/qemufuzzer/src/lib.rs @@ -7,7 +7,7 @@ use afl::engines::Engine; use afl::engines::Fuzzer; use afl::engines::State; use afl::engines::StdFuzzer; -use afl::events::{SimpleStats, LlmpEventManager}; +use afl::events::{LlmpEventManager, SimpleStats}; use afl::executors::inmemory::InMemoryExecutor; use afl::executors::{Executor, ExitKind}; use afl::feedbacks::MaxMapFeedback; @@ -66,7 +66,10 @@ pub extern "C" fn fuzz_main_loop() { } println!("We're a client, let's fuzz :)"); - let edges_observer = VariableMapObserver::new(&NAME_COV_MAP, unsafe { &mut fuzz_hitcounts_map }, unsafe { &fuzz_edges_id }); + let edges_observer = + VariableMapObserver::new(&NAME_COV_MAP, unsafe { &mut fuzz_hitcounts_map }, unsafe { + &fuzz_edges_id + }); let edges_feedback = MaxMapFeedback::new_with_observer(&NAME_COV_MAP, &edges_observer); let executor = InMemoryExecutor::new("QEMUFuzzer", harness, tuple_list!(edges_observer));