From 5a382cc35167b7abd4a6a58da9ca8c58260035f3 Mon Sep 17 00:00:00 2001 From: Andrea Fioraldi Date: Sun, 6 Dec 2020 12:03:27 +0100 Subject: [PATCH] fix handle_in_client borrow, remove testcase.clone() --- afl/Cargo.toml | 3 +-- afl/src/corpus/testcase.rs | 1 - afl/src/events/mod.rs | 23 ++++++++++------------- afl/src/feedbacks/mod.rs | 1 - 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/afl/Cargo.toml b/afl/Cargo.toml index e598a8f3e0..50fe3da885 100644 --- a/afl/Cargo.toml +++ b/afl/Cargo.toml @@ -8,7 +8,6 @@ edition = "2018" [dev-dependencies] criterion = "0.3" # Benchmarking -xxhash-rust = { version = "0.8.0-beta.5", features = ["const_xxh3", "xxh3"] } # xxh3 hashing for rust ahash = "0.6.1" # another hash fxhash = "0.2.1" # yet another hash @@ -30,7 +29,7 @@ std = [] hashbrown = { version = "0.9", features = ["serde"] } # A faster hashmap, nostd compatible libc = "0.2" # For (*nix) libc num = "*" -xxhash-rust = { version = "0.8.0-beta.5", features = ["xxh3"] } # xxh3 hashing for rust +xxhash-rust = { version = "0.8.0-beta.5", features = ["const_xxh3", "xxh3"] } # xxh3 hashing for rust serde = { version = "1.0", default-features = false, features = ["alloc"] } # serialization lib erased-serde = "0.3.12" postcard = "0.5.1" # no_std compatible serde serialization fromat diff --git a/afl/src/corpus/testcase.rs b/afl/src/corpus/testcase.rs index 852be0e544..daca24ef74 100644 --- a/afl/src/corpus/testcase.rs +++ b/afl/src/corpus/testcase.rs @@ -4,7 +4,6 @@ use core::cell::RefCell; use core::convert::Into; use core::default::Default; use core::option::Option; -use hashbrown::HashMap; use serde::{Deserialize, Serialize}; use crate::inputs::Input; diff --git a/afl/src/events/mod.rs b/afl/src/events/mod.rs index 487be3ad1c..42c104a693 100644 --- a/afl/src/events/mod.rs +++ b/afl/src/events/mod.rs @@ -214,7 +214,7 @@ where } fn handle_in_client( - &self, + self, /*client: &dyn EventManager,*/ _state: &mut S, corpus: &mut C, ) -> Result<(), AflError> { @@ -224,7 +224,7 @@ where testcase, phantom: _, } => { - corpus.add(testcase.clone()); + corpus.add(testcase); Ok(()) } _ => Err(AflError::Unknown( @@ -315,19 +315,16 @@ where for x in self.events.iter() { handled.push(x.handle_in_broker(state, corpus)?); } - handled - .iter() - .zip(self.events.iter()) - .map(|(x, event)| match x { - BrokerEventResult::Forward => event.handle_in_client(state, corpus), - // Ignore broker-only events - BrokerEventResult::Handled => Ok(()), - }) - .for_each(drop); let count = self.events.len(); + while self.events.len() > 0 { + let event = self.events.pop().unwrap(); + match handled.pop().unwrap() { + BrokerEventResult::Forward => event.handle_in_client(state, corpus)?, + // Ignore broker-only events + BrokerEventResult::Handled => (), + } + } dbg!("Handled {} events", count); - self.events.clear(); - Ok(count) } } diff --git a/afl/src/feedbacks/mod.rs b/afl/src/feedbacks/mod.rs index 541a17aaa9..294b9eed85 100644 --- a/afl/src/feedbacks/mod.rs +++ b/afl/src/feedbacks/mod.rs @@ -1,4 +1,3 @@ -use alloc::boxed::Box; use alloc::rc::Rc; use alloc::vec::Vec; use core::cell::RefCell;