From 194ac619be97513d6bd5ef32562f6ede05c8042a Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Sat, 14 Nov 2020 09:39:55 +0100 Subject: [PATCH] removed _rr funcs --- src/corpus/mod.rs | 8 ++++---- src/corpus/testcase.rs | 23 +++++++++++------------ src/engines/mod.rs | 13 +++---------- src/executors/inmemory.rs | 12 +++++++++--- src/inputs/bytes.rs | 13 ++++++++++--- src/stages/mutational.rs | 2 +- src/utils.rs | 1 - 7 files changed, 38 insertions(+), 34 deletions(-) diff --git a/src/corpus/mod.rs b/src/corpus/mod.rs index 802927768d..347ce0a617 100644 --- a/src/corpus/mod.rs +++ b/src/corpus/mod.rs @@ -35,13 +35,13 @@ where /// Add an entry to the corpus #[allow(unused_mut)] - fn add(&mut self, mut entry: Rc>>) { - self.entries_mut().push(entry); + fn add(&mut self, mut testcase: Rc>>) { + self.entries_mut().push(testcase); } /// Add an input to the corpus fn add_input(&mut self, input: I) { - self.add(Testcase::new_rr(input)); + self.add(Testcase::new(input.into()).into()); } /// Removes an entry from the corpus, returning it if it was present. @@ -368,7 +368,7 @@ mod tests { let rand: Rc<_> = DefaultRand::preseeded().into(); let mut q = QueueCorpus::new(OnDiskCorpus::new(&rand, PathBuf::from("fancy/path"))); let i = BytesInput::new(vec![0; 4]); - let t = Testcase::with_filename_rr(i, PathBuf::from("fancyfile")); + let t: Rc<_> = Testcase::with_filename(i, PathBuf::from("fancyfile")).into(); q.add(t); let filename = q .next() diff --git a/src/corpus/testcase.rs b/src/corpus/testcase.rs index da56cda41d..5a13f3b329 100644 --- a/src/corpus/testcase.rs +++ b/src/corpus/testcase.rs @@ -5,6 +5,7 @@ use crate::AflError; use alloc::rc::Rc; use core::cell::RefCell; +use core::convert::Into; use hashbrown::HashMap; use std::fs::File; use std::io::Write; @@ -113,6 +114,16 @@ where metadatas: HashMap<&'static str, Box>, } +impl Into>> for Testcase +where + I: Input, +{ + fn into(self) -> Rc> { + Rc::new(RefCell::new(self)) + } +} + + /// Impl of a testcase impl Testcase where @@ -181,16 +192,4 @@ where } } - /// Create a new Testcase instace given an input behind a Rc RefCell - pub fn new_rr(input: T) -> Rc> - where - T: Into, - { - Rc::new(RefCell::new(Self::new(input.into()))) - } - - /// Create a new Testcase instace given an input and a filename behind a Rc RefCell - pub fn with_filename_rr(input: I, filename: PathBuf) -> Rc> { - Rc::new(RefCell::new(Self::with_filename(input, filename))) - } } diff --git a/src/engines/mod.rs b/src/engines/mod.rs index a3fabac95c..6efc24f3fb 100644 --- a/src/engines/mod.rs +++ b/src/engines/mod.rs @@ -1,9 +1,6 @@ //! The engine is the core piece of every good fuzzer extern crate alloc; -use alloc::rc::Rc; -use core::cell::RefCell; - use crate::corpus::Corpus; use crate::feedbacks::Feedback; use crate::inputs::Input; @@ -81,10 +78,7 @@ where stages: vec![], } } - - pub fn new_rr() -> Rc> { - Rc::new(RefCell::new(Self::new())) - } + } #[cfg(test)] @@ -110,13 +104,12 @@ mod tests { #[test] fn test_engine() { - // TODO: Replace _rr with .Into traits let rand: Rc<_> = DefaultRand::preseeded().into(); let mut corpus = InMemoryCorpus::::new(&rand); - let testcase = Testcase::new_rr(vec![0; 4]); + let testcase = Testcase::new(BytesInput::new(vec![0; 4])).into(); corpus.add(testcase); - let executor: Rc>> = InMemoryExecutor::new_rr(harness); + let executor: Rc>> = InMemoryExecutor::new(harness).into(); let mut engine = DefaultEngine::new(); let mut mutator = DefaultScheduledMutator::new(&rand); mutator.add_mutation(mutation_bitflip); diff --git a/src/executors/inmemory.rs b/src/executors/inmemory.rs index 778367fa96..4e99e08ff1 100644 --- a/src/executors/inmemory.rs +++ b/src/executors/inmemory.rs @@ -22,6 +22,15 @@ where feedbacks: Vec>>, } +impl Into>> for InMemoryExecutor +where + I: Input, +{ + fn into(self) -> Rc> { + Rc::new(RefCell::new(self)) + } +} + static mut CURRENT_INMEMORY_EXECUTOR_PTR: *const c_void = ptr::null(); impl Executor for InMemoryExecutor @@ -90,9 +99,6 @@ where } } - pub fn new_rr(harness_fn: HarnessFunction) -> Rc> { - Rc::new(RefCell::new(Self::new(harness_fn))) - } } #[cfg(unix)] diff --git a/src/inputs/bytes.rs b/src/inputs/bytes.rs index 06c324c31a..a2c288c255 100644 --- a/src/inputs/bytes.rs +++ b/src/inputs/bytes.rs @@ -2,9 +2,8 @@ extern crate alloc; use core::convert::From; -use core::convert::TryFrom; -use std::fs::File; -use std::path::Path; +use core::cell::RefCell; +use alloc::rc::Rc; use crate::inputs::{HasBytesVec, HasTargetBytes, Input}; use crate::AflError; @@ -25,6 +24,14 @@ impl Input for BytesInput { } } +/// Rc Ref-cell from Input +impl Into>> for BytesInput { + fn into(self) -> Rc> { + Rc::new(RefCell::new(self)) + } +} + + impl HasBytesVec for BytesInput { fn bytes(&self) -> &Vec { &self.bytes diff --git a/src/stages/mutational.rs b/src/stages/mutational.rs index fe4fce4cdc..a38555b61b 100644 --- a/src/stages/mutational.rs +++ b/src/stages/mutational.rs @@ -53,7 +53,7 @@ where self.mutator_mut().post_exec(interesting, i as i32)?; if interesting { - corpus.add(Testcase::new_rr(input_tmp)); + corpus.add(Testcase::new(input_tmp).into()); } } Ok(()) diff --git a/src/utils.rs b/src/utils.rs index 49934fa4b9..21d383e6af 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -109,7 +109,6 @@ impl Rand for Xoshiro256StarRand { } } -use std::convert::Into; impl Into>> for Xoshiro256StarRand { fn into(self) -> Rc> { Rc::new(RefCell::new(self))