From 3e6bca34f1f40f494bdafc766740c889221ff524 Mon Sep 17 00:00:00 2001 From: Andrea Fioraldi Date: Thu, 5 Nov 2020 20:12:20 +0100 Subject: [PATCH] update broken engine --- src/engines/mod.rs | 27 ++++++++++++++------------- src/executors/inmemory.rs | 34 ++++++---------------------------- src/executors/mod.rs | 13 ++----------- src/feedbacks/mod.rs | 13 +++---------- 4 files changed, 25 insertions(+), 62 deletions(-) diff --git a/src/engines/mod.rs b/src/engines/mod.rs index 3aa345f96b..41398355b9 100644 --- a/src/engines/mod.rs +++ b/src/engines/mod.rs @@ -63,25 +63,22 @@ where input: &mut I, entry: Rc>>, ) -> Result { - { - self.executor_mut().reset_observers()?; - // self.executor_mut().place_input(Box::new(input))?; - - self.executor_mut().run_target()?; - - self.executor_mut().post_exec_observers()?; - } + self.executor_mut().reset_observers()?; + self.executor_mut().run_target(input)?; + self.executor_mut().post_exec_observers()?; // TODO new method for this shit - let mut new_entry: Option>>> = None; // lazy init + let mut new_entry: Rc>> = + Rc::new(RefCell::new(Testcase::::default())); // lazy init let mut rate_acc = 0; for feedback in self.feedbacks_mut() { - let (rate, meta) = feedback.is_interesting(self.executor_mut()); + let (rate, meta) = feedback.is_interesting(input); rate_acc += rate; if let Some(m) = meta { - //if new_entry.is_none() { - new_entry = Some(Rc::new(RefCell::new(Testcase::::new(input.clone())))); - //} + if let Some(_) = new_entry { + } else { + new_entry = Some(Rc::new(RefCell::new(Testcase::::new(input.clone())))); + } new_entry .unwrap() .borrow_mut() @@ -89,6 +86,10 @@ where } } + if rate_acc >= 25 { + self.corpus_mut().add(new_entry.unwrap().clone()); + } + Ok(true) } } diff --git a/src/executors/inmemory.rs b/src/executors/inmemory.rs index a4c9d3adad..e36d4bb732 100644 --- a/src/executors/inmemory.rs +++ b/src/executors/inmemory.rs @@ -13,7 +13,6 @@ pub struct InMemoryExecutor where I: Input, { - cur_input: Option>, observers: Vec>, harness: HarnessFunction, } @@ -24,35 +23,16 @@ impl Executor for InMemoryExecutor where I: Input, { - fn run_target(&mut self) -> Result { - let bytes = match self.cur_input.as_ref() { - Some(i) => i.serialize(), - None => return Err(AflError::Empty("cur_input".to_string())), - }; + fn run_target(&mut self, input: &mut I) -> Result { + let bytes = input.serialize()?; unsafe { CURRENT_INMEMORY_EXECUTOR_PTR = self as *const InMemoryExecutor as *const c_void; } - let ret = match bytes { - Ok(b) => Ok((self.harness)(self, b)), - Err(e) => Err(e), - }; + let ret = (self.harness)(self, bytes); unsafe { CURRENT_INMEMORY_EXECUTOR_PTR = ptr::null(); } - ret - } - - fn place_input(&mut self, input: Box) -> Result<(), AflError> { - self.cur_input = Some(input); - Ok(()) - } - - fn cur_input(&self) -> &Option> { - &self.cur_input - } - - fn cur_input_mut(&mut self) -> &mut Option> { - &mut self.cur_input + Ok(ret) } fn reset_observers(&mut self) -> Result<(), AflError> { @@ -87,7 +67,6 @@ where os_signals::setup_crash_handlers::(); } InMemoryExecutor { - cur_input: None, observers: vec![], harness: harness_fn, } @@ -232,8 +211,7 @@ mod tests { #[test] fn test_inmem_exec() { let mut in_mem_executor = InMemoryExecutor::new(test_harness_fn_nop); - let input = NopInput {}; - assert!(in_mem_executor.place_input(Box::new(input)).is_ok()); - assert!(in_mem_executor.run_target().is_ok()); + let mut input = NopInput {}; + assert!(in_mem_executor.run_target(&mut input).is_ok()); } } diff --git a/src/executors/mod.rs b/src/executors/mod.rs index f82e4694d4..60c7d8b987 100644 --- a/src/executors/mod.rs +++ b/src/executors/mod.rs @@ -17,17 +17,8 @@ pub trait Executor where I: Input, { - /// Run the target - fn run_target(&mut self) -> Result; - - /// Instruct the target about the input before the run - fn place_input(&mut self, input: Box) -> Result<(), AflError>; - - /// Get the current input, if any - fn cur_input(&self) -> &Option>; - - /// Get the current input, if any (mutable) - fn cur_input_mut(&mut self) -> &mut Option>; + /// Instruct the target about the input and run + fn run_target(&mut self, input: &mut I) -> Result; /// Reset the state of all the observes linked to this executor fn reset_observers(&mut self) -> Result<(), AflError>; diff --git a/src/feedbacks/mod.rs b/src/feedbacks/mod.rs index dfc92aa7e7..c0efef5661 100644 --- a/src/feedbacks/mod.rs +++ b/src/feedbacks/mod.rs @@ -1,7 +1,6 @@ extern crate num; -use crate::corpus::{Testcase, TestcaseMetadata}; -use crate::executors::Executor; +use crate::corpus::TestcaseMetadata; use crate::inputs::Input; use crate::observers::MapObserver; @@ -14,10 +13,7 @@ where I: Input, { /// is_interesting should return the "Interestingness" from 0 to 255 (percent times 2.55) - fn is_interesting( - &mut self, - executor: &dyn Executor, - ) -> (u32, Option>); + fn is_interesting(&mut self, input: &I) -> (u32, Option>); } /// A Reducer function is used to aggregate values for the novelty search @@ -90,10 +86,7 @@ where O: MapObserver, I: Input, { - fn is_interesting( - &mut self, - _executor: &dyn Executor, - ) -> (u32, Option>) { + fn is_interesting(&mut self, _input: &I) -> (u32, Option>) { let mut interesting = 0; // TODO: impl. correctly, optimize