NewTestcase2 -> NewTestcase

This commit is contained in:
Andrea Fioraldi 2020-12-09 12:32:14 +01:00
parent 6c917cc385
commit 24e01d89b5
5 changed files with 25 additions and 55 deletions

View File

@ -3,8 +3,8 @@ pub use testcase::{Testcase, TestcaseMetadata};
use alloc::borrow::ToOwned; use alloc::borrow::ToOwned;
use alloc::vec::Vec; use alloc::vec::Vec;
use core::marker::PhantomData;
use core::cell::RefCell; use core::cell::RefCell;
use core::marker::PhantomData;
use core::ptr; use core::ptr;
#[cfg(feature = "std")] #[cfg(feature = "std")]
@ -61,7 +61,11 @@ where
/// Removes an entry from the corpus, returning it if it was present. /// Removes an entry from the corpus, returning it if it was present.
fn remove(&mut self, entry: &Testcase<I>) -> Option<Testcase<I>> { fn remove(&mut self, entry: &Testcase<I>) -> Option<Testcase<I>> {
match self.entries().iter().position(|x| ptr::eq(x.as_ptr(), entry)) { match self
.entries()
.iter()
.position(|x| ptr::eq(x.as_ptr(), entry))
{
Some(i) => Some(self.entries_mut().remove(i).into_inner()), Some(i) => Some(self.entries_mut().remove(i).into_inner()),
None => None, None => None,
} }
@ -99,7 +103,6 @@ where
} }
Ok(()) Ok(())
}*/ }*/
// TODO: IntoIter // TODO: IntoIter
/// Gets the next entry /// Gets the next entry
fn next(&mut self, rand: &mut R) -> Result<(&RefCell<Testcase<I>>, usize), AflError>; fn next(&mut self, rand: &mut R) -> Result<(&RefCell<Testcase<I>>, usize), AflError>;

View File

@ -102,11 +102,7 @@ where
// TODO move some of these, like evaluate_input, to FuzzingEngine // TODO move some of these, like evaluate_input, to FuzzingEngine
/// Runs the input and triggers observers and feedback /// Runs the input and triggers observers and feedback
pub fn evaluate_input<E>( pub fn evaluate_input<E>(&mut self, input: &I, executor: &mut E) -> Result<u32, AflError>
&mut self,
input: &I,
executor: &mut E,
) -> Result<u32, AflError>
where where
E: Executor<I>, E: Executor<I>,
{ {
@ -404,7 +400,13 @@ mod tests {
for i in 0..1000 { for i in 0..1000 {
fuzzer fuzzer
.fuzz_one(&mut rand, &mut state, &mut corpus, &mut engine, &mut events_manager) .fuzz_one(
&mut rand,
&mut state,
&mut corpus,
&mut engine,
&mut events_manager,
)
.expect(&format!("Error in iter {}", i)); .expect(&format!("Error in iter {}", i));
} }
} }

View File

@ -17,7 +17,7 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::io::Write; use std::io::Write;
use crate::corpus::{Corpus, Testcase}; use crate::corpus::Corpus;
use crate::engines::State; use crate::engines::State;
use crate::executors::Executor; use crate::executors::Executor;
use crate::inputs::Input; use crate::inputs::Input;
@ -81,11 +81,6 @@ where
phantom: PhantomData<(C, E, I, R)>, phantom: PhantomData<(C, E, I, R)>,
}, },
NewTestcase { NewTestcase {
sender_id: u64,
testcase: Testcase<I>,
phantom: PhantomData<(C, E, I, R)>,
},
NewTestcase2 {
sender_id: u64, sender_id: u64,
input: Ptr<'a, I>, input: Ptr<'a, I>,
observers: PtrMut<'a, crate::observers::observer_serde::NamedSerdeAnyMap>, observers: PtrMut<'a, crate::observers::observer_serde::NamedSerdeAnyMap>,
@ -132,15 +127,10 @@ where
phantom: _, phantom: _,
} => "Initial", } => "Initial",
Event::NewTestcase { Event::NewTestcase {
sender_id: _,
testcase: _,
phantom: _,
} => "New Testcase",
Event::NewTestcase2 {
sender_id: _, sender_id: _,
input: _, input: _,
observers: _, observers: _,
} => "New Testcase 2", } => "New Testcase",
Event::UpdateStats { Event::UpdateStats {
sender_id: _, sender_id: _,
new_execs: _, new_execs: _,
@ -167,6 +157,7 @@ where
} }
} }
// TODO the broker has a state? do we need to pass state and corpus?
fn handle_in_broker( fn handle_in_broker(
&self, &self,
/*broker: &dyn EventManager<C, E, I, R>,*/ _state: &mut State<I, R>, /*broker: &dyn EventManager<C, E, I, R>,*/ _state: &mut State<I, R>,
@ -178,11 +169,6 @@ where
phantom: _, phantom: _,
} => Ok(BrokerEventResult::Handled), } => Ok(BrokerEventResult::Handled),
Event::NewTestcase { Event::NewTestcase {
sender_id: _,
testcase: _,
phantom: _,
} => Ok(BrokerEventResult::Forward),
Event::NewTestcase2 {
sender_id: _, sender_id: _,
input: _, input: _,
observers: _, observers: _,
@ -235,10 +221,12 @@ where
match self { match self {
Event::NewTestcase { Event::NewTestcase {
sender_id: _, sender_id: _,
testcase, input: _,
phantom: _, observers: _,
} => { } => {
corpus.add(testcase); // here u should match sender_id, if equal to the current one do not re-execute
// we need to pass engine to process() too, TODO
println!("PLACEHOLDER: received NewTestcase");
Ok(()) Ok(())
} }
_ => Err(AflError::Unknown( _ => Err(AflError::Unknown(

View File

@ -8,6 +8,8 @@ use serde::{Deserialize, Serialize};
use crate::serde_anymap::{SerdeAny, SliceMut}; use crate::serde_anymap::{SerdeAny, SliceMut};
use crate::AflError; use crate::AflError;
// TODO register each observer in the Registry in new()
/// Observers observe different information about the target. /// Observers observe different information about the target.
/// They can then be used by various sorts of feedback. /// They can then be used by various sorts of feedback.
pub trait Observer: SerdeAny + 'static { pub trait Observer: SerdeAny + 'static {
@ -26,31 +28,6 @@ pub trait Observer: SerdeAny + 'static {
crate::create_serde_registry_for_trait!(observer_serde, crate::observers::Observer); crate::create_serde_registry_for_trait!(observer_serde, crate::observers::Observer);
#[derive(Serialize, Deserialize)]
pub struct NopObserver {}
impl Observer for NopObserver {
fn name(&self) -> &'static str {
"aa"
}
fn reset(&mut self) -> Result<(), AflError> {
Ok(())
}
}
impl SerdeAny for NopObserver {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
impl NopObserver {
pub fn new() -> Self {
Self {}
}
}
/// A MapObserver observes the static map, as oftentimes used for afl-like coverage information /// A MapObserver observes the static map, as oftentimes used for afl-like coverage information
pub trait MapObserver<T> pub trait MapObserver<T>
where where

View File

@ -65,7 +65,7 @@ where
if let Some(mut testcase) = testcase_maybe { if let Some(mut testcase) = testcase_maybe {
// TODO decouple events manager and engine // TODO decouple events manager and engine
manager.fire( manager.fire(
Event::NewTestcase2 { Event::NewTestcase {
sender_id: 0, sender_id: 0,
input: Ptr::Ref(testcase.load_input()?), input: Ptr::Ref(testcase.load_input()?),
observers: PtrMut::Ref(engine.executor_mut().observers_mut()), observers: PtrMut::Ref(engine.executor_mut().observers_mut()),