diff --git a/afl/src/corpus/mod.rs b/afl/src/corpus/mod.rs index 95fc939cba..92d047adf4 100644 --- a/afl/src/corpus/mod.rs +++ b/afl/src/corpus/mod.rs @@ -1,12 +1,12 @@ pub mod testcase; -pub use testcase::{Testcase}; +pub use testcase::Testcase; use alloc::borrow::ToOwned; use alloc::vec::Vec; use core::cell::RefCell; use core::marker::PhantomData; use core::ptr; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; #[cfg(feature = "std")] use std::path::PathBuf; diff --git a/afl/src/engines/mod.rs b/afl/src/engines/mod.rs index 5475701d00..791e2c7156 100644 --- a/afl/src/engines/mod.rs +++ b/afl/src/engines/mod.rs @@ -2,7 +2,7 @@ use core::fmt::Debug; use core::marker::PhantomData; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use crate::corpus::{Corpus, Testcase}; use crate::events::EventManager; @@ -11,8 +11,8 @@ use crate::feedbacks::FeedbacksTuple; use crate::generators::Generator; use crate::inputs::Input; use crate::observers::ObserversTuple; -use crate::stages::StagesTuple; use crate::serde_anymap::{SerdeAny, SerdeAnyMap}; +use crate::stages::StagesTuple; use crate::tuples::{tuple_list, tuple_list_type}; use crate::utils::{current_milliseconds, Rand}; use crate::AflError; @@ -420,7 +420,7 @@ mod tests { use crate::inputs::bytes::BytesInput; use crate::mutators::{mutation_bitflip, ComposedByMutations, StdScheduledMutator}; use crate::stages::mutational::StdMutationalStage; - use crate::tuples::{tuple_list_type, tuple_list}; + use crate::tuples::{tuple_list, tuple_list_type}; use crate::utils::StdRand; fn harness(_executor: &dyn Executor, _buf: &[u8]) -> ExitKind { @@ -460,11 +460,13 @@ mod tests { } let state_serialized = postcard::to_allocvec(&state).unwrap(); - let state_deserialized: State = postcard::from_bytes(state_serialized.as_slice()).unwrap(); + let state_deserialized: State = + postcard::from_bytes(state_serialized.as_slice()).unwrap(); assert_eq!(state.executions, state_deserialized.executions); let corpus_serialized = postcard::to_allocvec(&corpus).unwrap(); - let corpus_deserialized: InMemoryCorpus = postcard::from_bytes(corpus_serialized.as_slice()).unwrap(); + let corpus_deserialized: InMemoryCorpus = + postcard::from_bytes(corpus_serialized.as_slice()).unwrap(); assert_eq!(corpus.count(), corpus_deserialized.count()); } } diff --git a/afl/src/events/llmp.rs b/afl/src/events/llmp.rs index 13d09c5d7f..677ced499f 100644 --- a/afl/src/events/llmp.rs +++ b/afl/src/events/llmp.rs @@ -1135,7 +1135,6 @@ impl LlmpClient { } } -/* #[cfg(test)] mod tests { @@ -1143,6 +1142,7 @@ mod tests { use super::{ LlmpConnection::{self, IsBroker, IsClient}, + LlmpMsgHookResult::ForwardToClients, Tag, }; @@ -1167,15 +1167,19 @@ mod tests { // Give the (background) tcp thread a few millis to post the message sleep(Duration::from_millis(100)); - broker.once().unwrap(); + broker + .once(&mut |_sender_id, _tag, _msg| Ok(ForwardToClients)) + .unwrap(); let tag: Tag = 0x1337; let arr: [u8; 1] = [1u8]; // Send stuff client.send_buf(tag, &arr).unwrap(); // Forward stuff to clients - broker.once().unwrap(); - let (tag2, arr2) = client.recv_buf_blocking().unwrap(); + broker + .once(&mut |_sender_id, _tag, _msg| Ok(ForwardToClients)) + .unwrap(); + let (_sender_id, tag2, arr2) = client.recv_buf_blocking().unwrap(); assert_eq!(tag, tag2); assert_eq!(arr[0], arr2[0]); @@ -1183,4 +1187,3 @@ mod tests { assert_eq!(broker.llmp_clients.len(), 2); } } -*/ diff --git a/afl/src/executors/mod.rs b/afl/src/executors/mod.rs index e519424d73..23663953cd 100644 --- a/afl/src/executors/mod.rs +++ b/afl/src/executors/mod.rs @@ -1,6 +1,8 @@ pub mod inmemory; -use crate::inputs::Input; +use core::marker::PhantomData; + +use crate::inputs::{HasTargetBytes, Input}; use crate::observers::ObserversTuple; use crate::tuples::{MatchNameAndType, MatchType, Named, TupleList}; use crate::AflError; @@ -36,6 +38,31 @@ where } } +/// A simple executor that does nothing. +/// If intput len is 0, run_target will return Err +struct NopExecutor { + phantom: PhantomData, +} + +impl Executor for NopExecutor +where + I: Input + HasTargetBytes, +{ + fn run_target(&mut self, input: &I) -> Result { + if input.target_bytes().as_slice().len() == 0 { + Err(AflError::Empty("Input Empty".into())) + } else { + Ok(ExitKind::Ok) + } + } +} + +impl Named for NopExecutor { + fn name(&self) -> &str { + &"NopExecutor" + } +} + /// An executor takes the given inputs, and runs the harness/target. pub trait Executor: Named where @@ -77,3 +104,24 @@ where self.1.for_each_mut(f) } } + +#[cfg(test)] +mod test { + use core::marker::PhantomData; + + use crate::executors::Executor; + use crate::inputs::BytesInput; + + use super::NopExecutor; + + #[test] + fn nop_executor() { + let empty_input = BytesInput::new(vec![]); + let nonempty_input = BytesInput::new(vec![1u8]); + let mut executor = NopExecutor { + phantom: PhantomData, + }; + assert!(executor.run_target(&empty_input).is_err()); + assert!(executor.run_target(&nonempty_input).is_ok()); + } +}