save work and go to the grocery shop

This commit is contained in:
Andrea Fioraldi 2021-02-19 16:10:30 +01:00
parent a939f052d3
commit a3b30a2869
5 changed files with 34 additions and 23 deletions

View File

@ -22,16 +22,18 @@ where
I: Input, I: Input,
{ {
/// Mutate a given input /// Mutate a given input
fn mutate<S>( fn mutate<F, S>(
&mut self, &mut self,
fuzzer: &F,
state: &mut S, state: &mut S,
input: &mut I, input: &mut I,
stage_idx: i32, stage_idx: i32,
) -> Result<(), Error>; ) -> Result<(), Error>;
/// Post-process given the outcome of the execution /// Post-process given the outcome of the execution
fn post_exec<S>( fn post_exec<F, S>(
&mut self, &mut self,
_fuzzer: &F,
_state: &mut S, _state: &mut S,
_is_interesting: u32, _is_interesting: u32,
_stage_idx: i32, _stage_idx: i32,

View File

@ -27,21 +27,21 @@ pub enum MutationResult {
// TODO maybe the mutator arg is not needed // TODO maybe the mutator arg is not needed
/// The generic function type that identifies mutations /// The generic function type that identifies mutations
pub type MutationFunction<I, M, S> = pub type MutationFunction<I, F, M, S> =
fn(&mut M, &mut S, &mut I) -> Result<MutationResult, Error>; fn(&mut M, &F, &mut S, &mut I) -> Result<MutationResult, Error>;
pub trait ComposedByMutations<I, S> pub trait ComposedByMutations<I, F, S>
where where
I: Input, I: Input,
{ {
/// Get a mutation by index /// Get a mutation by index
fn mutation_by_idx(&self, index: usize) -> MutationFunction<I, Self, S>; fn mutation_by_idx(&self, index: usize) -> MutationFunction<I, F, Self, S>;
/// Get the number of mutations /// Get the number of mutations
fn mutations_count(&self) -> usize; fn mutations_count(&self) -> usize;
/// Add a mutation /// Add a mutation
fn add_mutation(&mut self, mutation: MutationFunction<I, Self, S>); fn add_mutation(&mut self, mutation: MutationFunction<I, F, Self, S>);
} }
/// Mem move in the own vec /// Mem move in the own vec
@ -939,6 +939,7 @@ pub fn read_tokens_file(f: &str, tokens: &mut Vec<Vec<u8>>) -> Result<u32, Error
Ok(entries) Ok(entries)
} }
/*
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#[cfg(feature = "std")] #[cfg(feature = "std")]
@ -1055,3 +1056,4 @@ token2="B"
*/ */
} }
} }
*/

View File

@ -34,8 +34,9 @@ where
/// New default implementation for mutate /// New default implementation for mutate
/// Implementations must forward mutate() to this method /// Implementations must forward mutate() to this method
fn scheduled_mutate( fn scheduled_mutate<F>(
&mut self, &mut self,
fuzzer: &F,
state: &mut S, state: &mut S,
input: &mut I, input: &mut I,
_stage_idx: i32, _stage_idx: i32,

View File

@ -17,10 +17,11 @@ where
I: Input I: Input
{ {
/// Run the stage /// Run the stage
fn perform<E, EM, S>( fn perform<E, EM, F, S>(
&self, &self,
executor: &mut E, fuzzer: &F,
state: &mut S, state: &mut S,
executor: &mut E,
manager: &mut EM, manager: &mut EM,
corpus_idx: usize, corpus_idx: usize,
) -> Result<(), Error> ) -> Result<(), Error>
@ -33,10 +34,11 @@ pub trait StagesTuple<I>
where where
I: Input I: Input
{ {
fn perform_all<E, EM, S>( fn perform_all<E, EM, F, S>(
&self, &self,
executor: &mut E, fuzzer: &F,
state: &mut S, state: &mut S,
executor: &mut E,
manager: &mut EM, manager: &mut EM,
corpus_idx: usize, corpus_idx: usize,
) -> Result<(), Error> ) -> Result<(), Error>
@ -49,10 +51,11 @@ impl<I> StagesTuple<I> for ()
where where
I: Input I: Input
{ {
fn perform_all<E, EM, S>( fn perform_all<E, EM, F, S>(
&self, &self,
executor: &mut E, fuzzer: &F,
state: &mut S, state: &mut S,
executor: &mut E,
manager: &mut EM, manager: &mut EM,
corpus_idx: usize, corpus_idx: usize,
) -> Result<(), Error> ) -> Result<(), Error>
@ -70,10 +73,11 @@ where
Tail: StagesTuple<I> + TupleList, Tail: StagesTuple<I> + TupleList,
I: Input I: Input
{ {
fn perform_all<E, EM, S>( fn perform_all<E, EM, F, S>(
&self, &self,
executor: &mut E, fuzzer: &F,
state: &mut S, state: &mut S,
executor: &mut E,
manager: &mut EM, manager: &mut EM,
corpus_idx: usize, corpus_idx: usize,
) -> Result<(), Error> ) -> Result<(), Error>
@ -81,7 +85,7 @@ where
EM: EventManager<I>, EM: EventManager<I>,
E: Executor<I> E: Executor<I>
{ {
self.0.perform(executor, state, manager, corpus_idx)?; self.0.perform(fuzzer, state, executor, manager, corpus_idx)?;
self.1 .perform_all(executor, state, manager, corpus_idx) self.1 .perform_all(fuzzer, state, executor, manager, corpus_idx)
} }
} }

View File

@ -33,10 +33,11 @@ where
fn iterations<S>(&mut self, state: &mut S) -> usize; fn iterations<S>(&mut self, state: &mut S) -> usize;
/// Runs this (mutational) stage for the given testcase /// Runs this (mutational) stage for the given testcase
fn perform_mutational<E, EM, S, C>( fn perform_mutational<C, E, EM, F, S>(
&self, &self,
executor: &mut E, fuzzer: &F,
state: &mut S, state: &mut S,
executor: &mut E,
manager: &mut EM, manager: &mut EM,
corpus_idx: usize, corpus_idx: usize,
) -> Result<(), Error> ) -> Result<(), Error>
@ -111,10 +112,11 @@ where
I: Input, I: Input,
{ {
#[inline] #[inline]
fn perform<E, EM, S, C>( fn perform<C, E, EM, F, S>(
&self, &self,
executor: &mut E, fuzzer: &F,
state: &mut S, state: &mut S,
executor: &mut E,
manager: &mut EM, manager: &mut EM,
corpus_idx: usize, corpus_idx: usize,
) -> Result<(), Error> ) -> Result<(), Error>
@ -124,7 +126,7 @@ where
S: HasCorpus<C, I> + Evaluator<I>, S: HasCorpus<C, I> + Evaluator<I>,
C: Corpus<I> C: Corpus<I>
{ {
self.perform_mutational(executor, state, manager, corpus_idx) self.perform_mutational(fuzzer, state, executor, manager, corpus_idx)
} }
} }