testcase as arg for perform

This commit is contained in:
Andrea Fioraldi 2020-11-16 11:45:16 +01:00
parent 4fa50ebfaf
commit 056f5b6689
3 changed files with 21 additions and 6 deletions

View File

@ -31,8 +31,9 @@ where
} }
fn fuzz_one(&mut self, corpus: &mut C) -> Result<(), AflError> { fn fuzz_one(&mut self, corpus: &mut C) -> Result<(), AflError> {
let testcase = corpus.next()?;
for stage in self.stages_mut() { for stage in self.stages_mut() {
stage.perform(corpus)?; stage.perform(testcase.clone(), corpus)?;
} }
Ok(()) Ok(())
} }

View File

@ -1,9 +1,12 @@
pub mod mutational; pub mod mutational;
pub use mutational::DefaultMutationalStage; pub use mutational::DefaultMutationalStage;
use crate::corpus::testcase::Testcase;
use crate::corpus::Corpus; use crate::corpus::Corpus;
use crate::inputs::Input; use crate::inputs::Input;
use crate::AflError; use crate::AflError;
use alloc::rc::Rc;
use core::cell::RefCell;
pub trait Stage<C, I> pub trait Stage<C, I>
where where
@ -11,5 +14,9 @@ where
I: Input, I: Input,
{ {
/// Run the stage /// Run the stage
fn perform(&mut self, corpus: &mut C) -> Result<(), AflError>; fn perform(
&mut self,
testcase: Rc<RefCell<Testcase<I>>>,
corpus: &mut C,
) -> Result<(), AflError>;
} }

View File

@ -36,8 +36,11 @@ where
} }
/// Runs this (mutational) stage for the given testcase /// Runs this (mutational) stage for the given testcase
fn perform_mutational(&mut self, corpus: &mut C) -> Result<(), AflError> { fn perform_mutational(
let testcase = corpus.next()?; &mut self,
testcase: Rc<RefCell<Testcase<I>>>,
corpus: &mut C,
) -> Result<(), AflError> {
let num = self.iterations(); let num = self.iterations();
let input = testcase.borrow_mut().load_input()?.clone(); let input = testcase.borrow_mut().load_input()?.clone();
@ -120,8 +123,12 @@ where
M: Mutator<C, I, R = R>, M: Mutator<C, I, R = R>,
E: Executor<I>, E: Executor<I>,
{ {
fn perform(&mut self, corpus: &mut C) -> Result<(), AflError> { fn perform(
self.perform_mutational(corpus) &mut self,
testcase: Rc<RefCell<Testcase<I>>>,
corpus: &mut C,
) -> Result<(), AflError> {
self.perform_mutational(testcase, corpus)
} }
} }