From 1467d1fa9ca37c3e51906b2abb8805f89cff6158 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Fri, 11 Dec 2020 23:03:39 +0100 Subject: [PATCH] towards compilation --- afl/src/engines/mod.rs | 7 +++++-- afl/src/events/llmp.rs | 23 ++++++++++------------- afl/src/events/mod.rs | 40 ++++++++++++++++++++++++---------------- afl/src/utils.rs | 2 +- 4 files changed, 40 insertions(+), 32 deletions(-) diff --git a/afl/src/engines/mod.rs b/afl/src/engines/mod.rs index b02cf298ac..c766ee6ffe 100644 --- a/afl/src/engines/mod.rs +++ b/afl/src/engines/mod.rs @@ -115,12 +115,15 @@ where /// Adds a feedback #[inline] - pub fn add_feedback(&mut self, feedback: Box>) { + pub fn add_feedback(&mut self, feedback: Box) { self.feedbacks_mut().push(feedback); } // TODO move some of these, like evaluate_input, to FuzzingEngine - pub fn is_interesting(&mut self, input: &I, observers: &crate::observers::observer_serde::NamedSerdeAnyMap) -> Result { + pub fn is_interesting(&mut self, input: &I, observers: &OT) -> Result + where + OT: ObserversTuple, + { let mut fitness; for feedback in self.feedbacks_mut() { fitness += feedback.is_interesting(&input, observers)?; diff --git a/afl/src/events/llmp.rs b/afl/src/events/llmp.rs index ff4b5e8388..298c9178c8 100644 --- a/afl/src/events/llmp.rs +++ b/afl/src/events/llmp.rs @@ -238,12 +238,11 @@ impl LlmpConnection { /// Sends the given buffer over this connection, no matter if client or broker. pub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), AflError> { match self { - LlmpConnection::IsBroker {broker, listener_thread: _} => { - broker.send_buf(tag, buf) - }, - LlmpConnection::IsClient {client} => { - client.send_buf(tag, buf) - } + LlmpConnection::IsBroker { + broker, + listener_thread: _, + } => broker.send_buf(tag, buf), + LlmpConnection::IsClient { client } => client.send_buf(tag, buf), } } @@ -251,12 +250,11 @@ impl LlmpConnection { #[inline] pub fn recv_buf(&mut self) -> Result, AflError> { match self { - LlmpConnection::IsBroker {broker, listener_thread: _} => { - broker.recv_buf() - }, - LlmpConnection::IsClient {client} => { - client.recv_buf() - } + LlmpConnection::IsBroker { + broker, + listener_thread: _, + } => broker.recv_buf(), + LlmpConnection::IsClient { client } => client.recv_buf(), } } @@ -266,7 +264,6 @@ impl LlmpConnection { pub unsafe fn recv_blocking(&mut self) -> Result<*mut LlmpMsg, AflError> { self.llmp_in.recv_blocking() } - } /// Contents of the share mem pages, used by llmp internally diff --git a/afl/src/events/mod.rs b/afl/src/events/mod.rs index b1b40f3eb4..7dd73cf0b3 100644 --- a/afl/src/events/mod.rs +++ b/afl/src/events/mod.rs @@ -12,10 +12,12 @@ use serde::{Deserialize, Serialize}; //pub mod shmem_translated; #[cfg(feature = "std")] -use std::{io::Write, time::{SystemTime, UNIX_EPOCH}}; +use std::{ + io::Write, + time::{SystemTime, UNIX_EPOCH}, +}; use crate::corpus::Corpus; -use crate::{engines::State, utils}; use crate::executors::Executor; use crate::feedbacks::FeedbacksTuple; use crate::inputs::Input; @@ -23,6 +25,7 @@ use crate::observers::ObserversTuple; use crate::serde_anymap::{Ptr, PtrMut, SerdeAny}; use crate::utils::Rand; use crate::AflError; +use crate::{engines::State, utils}; /// Indicate if an event worked or not pub enum BrokerEventResult { @@ -201,14 +204,18 @@ where /// Total executions #[inline] fn total_execs(&mut self) -> u64 { - self.client_stats().iter().fold(0u64, |acc, x| acc + x.executions) + self.client_stats() + .iter() + .fold(0u64, |acc, x| acc + x.executions) } /// Executions per second #[inline] fn execs_per_sec(&mut self) -> u64 { let time_since_start = (utils::current_time() - self.start_time()).as_secs(); - if time_since_start == 0 { 0 } else { + if time_since_start == 0 { + 0 + } else { self.total_execs() / time_since_start } } @@ -225,7 +232,9 @@ where self.corpus_size_inc(); println!( "[NEW] corpus: {} execs: {} execs/s: {}", - self.corpus_size(), self.total_execs(), self.execs_per_sec() + self.corpus_size(), + self.total_execs(), + self.execs_per_sec() ); Ok(BrokerEventResult::Forward) } @@ -242,13 +251,15 @@ where id: client_stat_count + i, corpus_size: 0, execs_over_sec: 0, - executions: 0 + executions: 0, }) } let mut stat = &mut self.client_stats_mut()[*sender_id as usize]; println!( "[UPDATE] corpus: {} execs: {} execs/s: {}", - self.corpus_size(), self.total_execs(), self.execs_per_sec() + self.corpus_size(), + self.total_execs(), + self.execs_per_sec() ); Ok(BrokerEventResult::Handled) } @@ -385,7 +396,6 @@ where fn start_time(&mut self) -> time::Duration { self.start_time } - } #[cfg(feature = "std")] @@ -414,7 +424,6 @@ where } } - #[cfg(feature = "std")] /// Forward this to the client const LLMP_TAG_EVENT_TO_CLIENT: llmp::Tag = 0x2C11E471; @@ -425,8 +434,6 @@ const _LLMP_TAG_EVENT_TO_BROKER: llmp::Tag = 0x2B80438; /// Handle in both const _LLMP_TAG_EVENT_TO_BOTH: llmp::Tag = 0x2B0741; - - #[cfg(feature = "std")] pub struct LlmpEventManager where @@ -451,7 +458,6 @@ impl EventManager for LlmpEventManager where C: Corpus, E: Executor, - OT: ObserversTuple, FT: FeedbacksTuple, I: Input, R: Rand, @@ -461,12 +467,15 @@ where #[inline] fn fire<'a>(&mut self, event: Event<'a, I>) -> Result<(), AflError> { let serialized = postcard::to_allocvec(&event)?; - self - .send_buf(LLMP_TAG_EVENT_TO_CLIENT, &serialized)?; + self.send_buf(LLMP_TAG_EVENT_TO_CLIENT, &serialized)?; Ok(()) } - fn process(&mut self, _state: &mut State, _corpus: &mut C) -> Result { + fn process( + &mut self, + _state: &mut State, + _corpus: &mut C, + ) -> Result { let c = self.count; self.count = 0; Ok(c) @@ -492,7 +501,6 @@ where fn start_time(&mut self) -> time::Duration { self.start_time } - } #[cfg(feature = "std")] diff --git a/afl/src/utils.rs b/afl/src/utils.rs index 72aad80edc..08f188ca25 100644 --- a/afl/src/utils.rs +++ b/afl/src/utils.rs @@ -1,9 +1,9 @@ //! Utility functions for AFL use alloc::rc::Rc; -use core::{cell::RefCell, time}; use core::debug_assert; use core::fmt::Debug; +use core::{cell::RefCell, time}; use xxhash_rust::xxh3::xxh3_64_with_seed; #[cfg(feature = "std")]