diff --git a/afl/llmp_test/src/main.rs b/afl/llmp_test/src/main.rs index 80f777f65c..9a72ccd955 100644 --- a/afl/llmp_test/src/main.rs +++ b/afl/llmp_test/src/main.rs @@ -1,3 +1,6 @@ +#[macro_use] +extern crate alloc; + use core::convert::TryInto; use core::ffi::c_void; use core::mem::size_of; @@ -16,7 +19,7 @@ unsafe fn llmp_test_clientloop(client: *mut llmp_client, _data: *mut c_void) -> counter += 1; let llmp_message = llmp_client_alloc_next(client, size_of::()); - std::ptr::copy( + core::ptr::copy( counter.to_be_bytes().as_ptr(), (*llmp_message).buf.as_mut_ptr(), size_of::(), @@ -30,7 +33,7 @@ unsafe fn llmp_test_clientloop(client: *mut llmp_client, _data: *mut c_void) -> unsafe fn u32_from_msg(message: *const llmp_message) -> u32 { u32::from_be_bytes( - std::slice::from_raw_parts((*message).buf.as_ptr(), size_of::()) + alloc::slice::from_raw_parts((*message).buf.as_ptr(), size_of::()) .try_into() .unwrap(), ) @@ -62,7 +65,7 @@ unsafe fn test_adder_clientloop(client: *mut llmp_client, _data: *mut c_void) -> ); let llmp_message = llmp_client_alloc_next(client, size_of::()); - std::ptr::copy( + core::ptr::copy( current_result.to_be_bytes().as_ptr(), (*llmp_message).buf.as_mut_ptr(), size_of::(), diff --git a/afl/src/events/mod.rs b/afl/src/events/mod.rs index 7c567068a0..f396ab522d 100644 --- a/afl/src/events/mod.rs +++ b/afl/src/events/mod.rs @@ -1,5 +1,10 @@ #[cfg(feature = "std")] pub mod llmp; + +use alloc::borrow::ToOwned; +use alloc::string::String; +use core::marker::PhantomData; + #[cfg(feature = "std")] pub mod llmp_translated; // TODO: Abstract away. #[cfg(feature = "std")] @@ -9,7 +14,7 @@ pub mod shmem_translated; pub use crate::events::llmp::LLMP; #[cfg(feature = "std")] -use std::{io::Write, marker::PhantomData}; +use std::io::Write; use crate::corpus::{Corpus, Testcase}; use crate::engines::State; @@ -190,6 +195,7 @@ where _marker, } => { //TODO: broker.log() + #[cfg(feature = "std")] println!("{}[{}]: {}", sender_id, severity_level, message); Ok(BrokerEventResult::Handled) } diff --git a/fuzzers/libfuzzer/src/lib.rs b/fuzzers/libfuzzer/src/lib.rs index f256505313..50111bfe95 100644 --- a/fuzzers/libfuzzer/src/lib.rs +++ b/fuzzers/libfuzzer/src/lib.rs @@ -1,7 +1,14 @@ -use std::boxed::Box; -use std::cell::RefCell; +#![cfg_attr(not(feature = "std"), no_std)] + +#[macro_use] +extern crate alloc; + +use alloc::boxed::Box; +use alloc::rc::Rc; +use core::cell::RefCell; + +#[cfg(feature = "std")] use std::io::stderr; -use std::rc::Rc; use afl::corpus::InMemoryCorpus; use afl::engines::{generate_initial_inputs, Engine, State, StdEngine, StdState}; @@ -40,6 +47,9 @@ pub extern "C" fn afl_libfuzzer_main() { let mut corpus = InMemoryCorpus::new(); let mut generator = RandPrintablesGenerator::new(32); + + // TODO: No_std event manager + #[cfg(feature = "std")] let mut events = LoggerEventManager::new(stderr()); let edges_observer = Rc::new(RefCell::new(StdMapObserver::new_from_ptr(