From c0b0ccccf30195fa32a6dbc4d98344eb4e260fa0 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Sun, 13 Dec 2020 22:37:05 +0100 Subject: [PATCH] more llmp --- afl/src/events/mod.rs | 52 +++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/afl/src/events/mod.rs b/afl/src/events/mod.rs index c2785b4a6d..9398ae38b2 100644 --- a/afl/src/events/mod.rs +++ b/afl/src/events/mod.rs @@ -352,6 +352,7 @@ where writer: W, count: usize, + events: Vec>, // stats (maybe we need a separated struct?) executions: usize, execs_over_sec: u64, @@ -377,7 +378,7 @@ where #[inline] fn fire<'a>(&mut self, event: Event) -> Result<(), AflError> { match self.handle_in_broker(&event)? { - BrokerEventResult::Forward => (), //self.handle_in_client(event, state, corpus)?, + BrokerEventResult::Forward => self.events.push(event), // Ignore broker-only events BrokerEventResult::Handled => (), } @@ -386,12 +387,13 @@ where fn process( &mut self, - _state: &mut State, - _corpus: &mut C, + state: &mut State, + corpus: &mut C, ) -> Result { - let c = self.count; - self.count = 0; - Ok(c) + let count = self.events.len(); + let events: Vec> = self.events.drain(..).collect(); + events.into_iter().try_for_each(|x| self.handle_in_client(x, state, corpus))?; + Ok(count) } fn client_stats_mut(&mut self) -> &mut Vec { @@ -438,6 +440,7 @@ where execs_over_sec: 0, corpus_size: 0, phantom: PhantomData, + events: vec![], } } } @@ -453,7 +456,7 @@ const _LLMP_TAG_EVENT_TO_BROKER: llmp::Tag = 0x2B80438; const _LLMP_TAG_EVENT_TO_BOTH: llmp::Tag = 0x2B0741; #[cfg(feature = "std")] -pub struct LlmpEventManager +pub struct LlmpEventManager where W: Write, //CE: CustomEvent, @@ -468,11 +471,11 @@ where start_time: time::Duration, client_stats: Vec, llmp: llmp::LlmpConnection, - phantom: PhantomData<(C, E, I, R)>, + phantom: PhantomData<(C, E, OT, FT, I, R)>, } #[cfg(feature = "std")] -impl EventManager for LlmpEventManager +impl EventManager for LlmpEventManager where C: Corpus, E: Executor, @@ -492,12 +495,33 @@ where fn process( &mut self, - _state: &mut State, - _corpus: &mut C, + state: &mut State, + corpus: &mut C, ) -> Result { - let c = self.count; - self.count = 0; - Ok(c) + let count = match &mut self.llmp { + llmp::LlmpConnection::IsClient {client} => { + let mut msg_count = 0; + loop { + + match client.recv_buf()? { + Some((tag, event_buf)) => { + if tag == _LLMP_TAG_EVENT_TO_BROKER { + continue; + } + let event = postcard::from_bytes(event_buf)?; + // TODO: self.handle_in_client(event, state, corpus)?; + msg_count += 1; + }, + None => break msg_count, + } + } + }, + _ => { + dbg!("Skipping process in broker"); + 0 + } + }; + Ok(count) } fn client_stats_mut(&mut self) -> &mut Vec {