diff --git a/afl/Cargo.toml b/afl/Cargo.toml index 81e5d8741c..1953e83bf0 100644 --- a/afl/Cargo.toml +++ b/afl/Cargo.toml @@ -21,7 +21,11 @@ harness = false name = "hash_speeds" harness = false - +[profile.release] +lto = true +codegen-units = 1 +opt-level = 3 +debug = true [features] default = ["std"] diff --git a/afl/src/engines/mod.rs b/afl/src/engines/mod.rs index 58ac453b19..f5a31360c3 100644 --- a/afl/src/engines/mod.rs +++ b/afl/src/engines/mod.rs @@ -213,14 +213,15 @@ where if !self.add_if_interesting(corpus, input, fitness)?.is_none() { added += 1; } - manager.fire( - Event::LoadInitial { - sender_id: 0, - phantom: PhantomData, - } - )?; + manager.fire(Event::LoadInitial { + sender_id: 0, + phantom: PhantomData, + })?; } - manager.fire(Event::log(0, format!("Loaded {} over {} initial testcases", added, num)))?; + manager.fire(Event::log( + 0, + format!("Loaded {} over {} initial testcases", added, num), + ))?; manager.process(self, corpus)?; Ok(()) } @@ -318,7 +319,10 @@ where let cur = current_milliseconds(); if cur - last > 60 * 100 { last = cur; - manager.fire(Event::update_stats(state.executions(), state.executions_over_seconds()))?; + manager.fire(Event::update_stats( + state.executions(), + state.executions_over_seconds(), + ))?; } } } diff --git a/afl/src/events/mod.rs b/afl/src/events/mod.rs index e8977a371b..12dfdbbc5b 100644 --- a/afl/src/events/mod.rs +++ b/afl/src/events/mod.rs @@ -60,7 +60,7 @@ where sender_id: u64, input: Ptr<'a, I>, observers: PtrMut<'a, crate::observers::observer_serde::NamedSerdeAnyMap>, - corpus_count: usize + corpus_count: usize, }, UpdateStats { sender_id: u64, @@ -109,7 +109,7 @@ where sender_id: _, input: _, observers: _, - corpus_count: _ + corpus_count: _, } => "New Testcase", Event::UpdateStats { sender_id: _, @@ -135,7 +135,7 @@ where } => "Log", Event::None { phantom: _ } => "None", Event::Custom { - sender_id, /*custom_event} => custom_event.name()*/ + sender_id: _, /*custom_event} => custom_event.name()*/ } => "todo", } } @@ -167,10 +167,7 @@ where R: Rand, { /// Fire an Event - fn fire<'a>( - &mut self, - event: Event<'a, I> - ) -> Result<(), AflError>; + fn fire<'a>(&mut self, event: Event<'a, I>) -> Result<(), AflError>; /// Lookup for incoming events and process them. /// Return the number of processes events or an error @@ -183,10 +180,7 @@ where } // TODO the broker has a state? do we need to pass state and corpus? - fn handle_in_broker( - &mut self, - event: &Event, - ) -> Result { + fn handle_in_broker(&mut self, event: &Event) -> Result { match event { Event::LoadInitial { sender_id: _, @@ -196,7 +190,7 @@ where sender_id: _, input: _, observers: _, - corpus_count: _ + corpus_count: _, } => Ok(BrokerEventResult::Forward), Event::UpdateStats { sender_id: _, @@ -233,7 +227,7 @@ where } Event::None { phantom: _ } => Ok(BrokerEventResult::Handled), Event::Custom { - sender_id, /*custom_event} => custom_event.handle_in_broker(state, corpus)*/ + sender_id: _, /*custom_event} => custom_event.handle_in_broker(state, corpus)*/ } => Ok(BrokerEventResult::Forward), //_ => Ok(BrokerEventResult::Forward), } @@ -250,7 +244,7 @@ where sender_id: _, input: _, observers: _, - corpus_count: _ + corpus_count: _, } => { // here u should match sender_id, if equal to the current one do not re-execute // we need to pass engine to process() too, TODO @@ -304,10 +298,7 @@ where W: Write, //CE: CustomEvent, { - fn fire<'a>( - &mut self, - event: Event<'a, I>, - ) -> Result<(), AflError> { + fn fire<'a>(&mut self, event: Event<'a, I>) -> Result<(), AflError> { match self.handle_in_broker(&event)? { BrokerEventResult::Forward => (), //self.handle_in_client(event, state, corpus)?, // Ignore broker-only events @@ -322,21 +313,22 @@ where Ok(c) } - fn handle_in_broker( - &mut self, - event: &Event, - ) -> Result { + fn handle_in_broker(&mut self, event: &Event) -> Result { match event { Event::NewTestcase { sender_id: _, input: _, observers: _, - corpus_count + corpus_count, } => { self.corpus_count = *corpus_count; - writeln!(self.writer, "[NEW] corpus: {} execs: {} execs/s: {}", self.corpus_count, self.executions, self.execs_over_sec); + writeln!( + self.writer, + "[NEW] corpus: {} execs: {} execs/s: {}", + self.corpus_count, self.executions, self.execs_over_sec + )?; Ok(BrokerEventResult::Handled) - }, + } Event::UpdateStats { sender_id: _, executions, @@ -345,7 +337,11 @@ where } => { self.executions = *executions; self.execs_over_sec = *execs_over_sec; - writeln!(self.writer, "[UPDATE] corpus: {} execs: {} execs/s: {}", self.corpus_count, self.executions, self.execs_over_sec); + writeln!( + self.writer, + "[UPDATE] corpus: {} execs: {} execs/s: {}", + self.corpus_count, self.executions, self.execs_over_sec + )?; Ok(BrokerEventResult::Handled) } Event::Crash { @@ -354,7 +350,7 @@ where phantom: _, } => { panic!("LoggerEventManager cannot handle Event::Crash"); - }, + } Event::Timeout { sender_id: _, input: _, @@ -363,12 +359,12 @@ where panic!("LoggerEventManager cannot handle Event::Timeout"); } Event::Log { - sender_id, + sender_id: _, severity_level, message, phantom: _, } => { - writeln!(self.writer, "[LOG {}]: {}", severity_level, message); + writeln!(self.writer, "[LOG {}]: {}", severity_level, message)?; Ok(BrokerEventResult::Handled) } _ => Ok(BrokerEventResult::Handled), @@ -417,10 +413,10 @@ where const LLMP_TAG_EVENT_TO_CLIENT: llmp::Tag = 0x2C11E471; #[cfg(feature = "std")] /// Only handle this in the broker -const LLMP_TAG_EVENT_TO_BROKER: llmp::Tag = 0x2B80438; +const _LLMP_TAG_EVENT_TO_BROKER: llmp::Tag = 0x2B80438; #[cfg(feature = "std")] /// Handle in both -const LLMP_TAG_EVENT_TO_BOTH: llmp::Tag = 0x2B0741; +const _LLMP_TAG_EVENT_TO_BOTH: llmp::Tag = 0x2B0741; /// Eventmanager for multi-processed application #[cfg(feature = "std")] @@ -432,7 +428,7 @@ where R: Rand, //CE: CustomEvent, { - llmp_client: llmp::LlmpClient, + _llmp_client: llmp::LlmpClient, phantom: PhantomData<(C, E, I, R)>, } @@ -445,10 +441,7 @@ where R: Rand, { /// Fire an Event - fn fire<'a>( - &mut self, - event: Event<'a, I>, - ) -> Result<(), AflError> { + fn fire<'a>(&mut self, event: Event<'a, I>) -> Result<(), AflError> { let serialized = postcard::to_allocvec(&event)?; self.llmp_broker .send_buf(LLMP_TAG_EVENT_TO_CLIENT, &serialized)?; @@ -490,10 +483,7 @@ where Ok(()) } - fn handle_in_broker( - &mut self, - event: &Event, - ) -> Result { + fn handle_in_broker(&mut self, event: &Event) -> Result { match event { Event::LoadInitial { sender_id: _, @@ -503,7 +493,7 @@ where sender_id: _, input: _, observers: _, - corpus_count: _ + corpus_count: _, } => Ok(BrokerEventResult::Forward), Event::UpdateStats { sender_id: _, @@ -540,7 +530,7 @@ where } Event::None { phantom: _ } => Ok(BrokerEventResult::Handled), Event::Custom { - sender_id, /*custom_event} => custom_event.handle_in_broker(state, corpus)*/ + sender_id: _, /*custom_event} => custom_event.handle_in_broker(state, corpus)*/ } => Ok(BrokerEventResult::Forward), //_ => Ok(BrokerEventResult::Forward), } @@ -550,14 +540,14 @@ where &mut self, event: Event, /*client: &dyn EventManager,*/ _state: &mut State, - corpus: &mut C, + _corpus: &mut C, ) -> Result<(), AflError> { match event { Event::NewTestcase { sender_id: _, input: _, observers: _, - corpus_count: _ + corpus_count: _, } => { // here u should match sender_id, if equal to the current one do not re-execute // we need to pass engine to process() too, TODO @@ -599,7 +589,7 @@ mod tests { sender_id: 0, input: Ptr::Ref(&i), observers: PtrMut::Ref(&mut map), - corpus_count: 1 + corpus_count: 1, }; let j = serde_json::to_string(&e).unwrap(); @@ -610,7 +600,7 @@ mod tests { sender_id: _, input: _, observers: obs, - corpus_count: _ + corpus_count: _, } => { let o = obs .as_ref() diff --git a/afl/src/inputs/mod.rs b/afl/src/inputs/mod.rs index d46aecad22..c1b227802d 100644 --- a/afl/src/inputs/mod.rs +++ b/afl/src/inputs/mod.rs @@ -3,8 +3,6 @@ pub use bytes::BytesInput; use alloc::vec::Vec; use core::clone::Clone; -#[cfg(feature = "std")] -use serde::{Deserialize, Serialize}; #[cfg(feature = "std")] use std::fs::File; diff --git a/afl/src/serde_anymap.rs b/afl/src/serde_anymap.rs index 521dac36bf..a903bedfcc 100644 --- a/afl/src/serde_anymap.rs +++ b/afl/src/serde_anymap.rs @@ -1,4 +1,4 @@ -use serde::{Deserialize, Serialize}; +use serde::Deserialize; use alloc::boxed::Box; use alloc::vec::Vec; diff --git a/afl/src/stages/mutational.rs b/afl/src/stages/mutational.rs index 498def3651..a7d79a9051 100644 --- a/afl/src/stages/mutational.rs +++ b/afl/src/stages/mutational.rs @@ -68,14 +68,12 @@ where let testcase_maybe = state.testcase_if_interesting(input_mut, fitness)?; if let Some(mut testcase) = testcase_maybe { // TODO decouple events manager and engine - manager.fire( - Event::NewTestcase { - sender_id: 0, - input: Ptr::Ref(testcase.load_input()?), - observers: PtrMut::Ref(engine.executor_mut().observers_mut()), - corpus_count: corpus.count() +1 - } - )?; + manager.fire(Event::NewTestcase { + sender_id: 0, + input: Ptr::Ref(testcase.load_input()?), + observers: PtrMut::Ref(engine.executor_mut().observers_mut()), + corpus_count: corpus.count() + 1, + })?; let _ = corpus.add(testcase); } } diff --git a/fuzzers/libfuzzer/Cargo.toml b/fuzzers/libfuzzer/Cargo.toml index 25079d3ca2..f31f776145 100644 --- a/fuzzers/libfuzzer/Cargo.toml +++ b/fuzzers/libfuzzer/Cargo.toml @@ -10,6 +10,12 @@ edition = "2018" default = ["std"] std = [] +[profile.release] +lto = true +codegen-units = 1 +opt-level = 3 +debug = true + [dependencies] afl = { path = "../../afl/" } diff --git a/fuzzers/libfuzzer/src/lib.rs b/fuzzers/libfuzzer/src/lib.rs index 662311784b..06666f188e 100644 --- a/fuzzers/libfuzzer/src/lib.rs +++ b/fuzzers/libfuzzer/src/lib.rs @@ -22,7 +22,7 @@ use afl::observers::StdMapObserver; use afl::stages::mutational::StdMutationalStage; use afl::utils::StdRand; -const MAP_SIZE: usize = 65536; +// const MAP_SIZE: usize = 65536; #[no_mangle] extern "C" {