Remove CustomBufHandlers (#2829)

* rem

* fix

* fixer
This commit is contained in:
Dongjia "toka" Zhang 2025-01-13 16:00:41 +01:00 committed by GitHub
parent aa0391ef8d
commit fd06e5ced0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 25 additions and 219 deletions

View File

@ -10,7 +10,7 @@
- `Qemu` cannot be used to initialize `Emulator` directly anymore. Instead, `Qemu` should be initialized through `Emulator` systematically if `Emulator` should be used. - `Qemu` cannot be used to initialize `Emulator` directly anymore. Instead, `Qemu` should be initialized through `Emulator` systematically if `Emulator` should be used.
- Related: `EmulatorBuilder` uses a single function to provide a `Qemu` initializer: `EmulatorBuilder::qemu_parameters`. For now, it can be either a `Vec<String>` or a `QemuConfig` instance. - Related: `EmulatorBuilder` uses a single function to provide a `Qemu` initializer: `EmulatorBuilder::qemu_parameters`. For now, it can be either a `Vec<String>` or a `QemuConfig` instance.
- Related: Qemu's `AsanModule` does not need any special call to `Qemu` init methods anymore. It is now possible to simply initialize `AsanModule` (or `AsanGuestModule`) with a reference to the environment as parameter. - Related: Qemu's `AsanModule` does not need any special call to `Qemu` init methods anymore. It is now possible to simply initialize `AsanModule` (or `AsanGuestModule`) with a reference to the environment as parameter.
- `CustomBufHandlers` has been deleted. Please use `EventManagerHooksTuple` from now on.
# 0.14.0 -> 0.14.1 # 0.14.0 -> 0.14.1
- Removed `with_observers` from `Executor` trait. - Removed `with_observers` from `Executor` trait.
- `MmapShMemProvider::new_shmem_persistent` has been removed in favour of `MmapShMem::persist`. You probably want to do something like this: `let shmem = MmapShMemProvider::new()?.new_shmem(size)?.persist()?;` - `MmapShMemProvider::new_shmem_persistent` has been removed in favour of `MmapShMem::persist`. You probably want to do something like this: `let shmem = MmapShMemProvider::new()?.new_shmem(size)?.persist()?;`

View File

@ -194,7 +194,6 @@ where
log::log!((*severity_level).into(), "{message}"); log::log!((*severity_level).into(), "{message}");
Ok(BrokerEventResult::Handled) Ok(BrokerEventResult::Handled)
} }
Event::CustomBuf { .. } => Ok(BrokerEventResult::Forward),
Event::Stop => Ok(BrokerEventResult::Forward), Event::Stop => Ok(BrokerEventResult::Forward),
//_ => Ok(BrokerEventResult::Forward), //_ => Ok(BrokerEventResult::Forward),
} }

View File

@ -7,7 +7,7 @@
// 3. The "main evaluator", the evaluator node that will evaluate all the testcases pass by the centralized event manager to see if the testcases are worth propagating // 3. The "main evaluator", the evaluator node that will evaluate all the testcases pass by the centralized event manager to see if the testcases are worth propagating
// 4. The "main broker", the gathers the stats from the fuzzer clients and broadcast the newly found testcases from the main evaluator. // 4. The "main broker", the gathers the stats from the fuzzer clients and broadcast the newly found testcases from the main evaluator.
use alloc::{boxed::Box, string::String, vec::Vec}; use alloc::{string::String, vec::Vec};
use core::{fmt::Debug, time::Duration}; use core::{fmt::Debug, time::Duration};
use std::{marker::PhantomData, process}; use std::{marker::PhantomData, process};
@ -30,9 +30,9 @@ use crate::events::llmp::COMPRESS_THRESHOLD;
use crate::{ use crate::{
corpus::Corpus, corpus::Corpus,
events::{ events::{
AdaptiveSerializer, CustomBufEventResult, Event, EventConfig, EventFirer, EventManager, AdaptiveSerializer, Event, EventConfig, EventFirer, EventManager, EventManagerHooksTuple,
EventManagerHooksTuple, EventManagerId, EventProcessor, EventRestarter, EventManagerId, EventProcessor, EventRestarter, HasEventManagerId, LogSeverity,
HasCustomBufHandlers, HasEventManagerId, LogSeverity, ProgressReporter, ProgressReporter,
}, },
executors::{Executor, HasObservers}, executors::{Executor, HasObservers},
fuzzer::{EvaluatorObservers, ExecutionProcessor}, fuzzer::{EvaluatorObservers, ExecutionProcessor},
@ -417,24 +417,6 @@ where
{ {
} }
impl<EM, EMH, S, SP> HasCustomBufHandlers for CentralizedEventManager<EM, EMH, S, SP>
where
EM: HasCustomBufHandlers<State = S>,
EMH: EventManagerHooksTuple<S>,
S: State,
SP: ShMemProvider,
{
/// Adds a custom buffer handler that will run for each incoming `CustomBuf` event.
fn add_custom_buf_handler(
&mut self,
handler: Box<
dyn FnMut(&mut Self::State, &str, &[u8]) -> Result<CustomBufEventResult, Error>,
>,
) {
self.inner.add_custom_buf_handler(handler);
}
}
impl<EM, EMH, S, SP> ProgressReporter for CentralizedEventManager<EM, EMH, S, SP> impl<EM, EMH, S, SP> ProgressReporter for CentralizedEventManager<EM, EMH, S, SP>
where where
EM: AdaptiveSerializer + ProgressReporter<State = S> + HasEventManagerId, EM: AdaptiveSerializer + ProgressReporter<State = S> + HasEventManagerId,

View File

@ -3,7 +3,7 @@
#[cfg(feature = "std")] #[cfg(feature = "std")]
use alloc::string::ToString; use alloc::string::ToString;
use alloc::{boxed::Box, vec::Vec}; use alloc::vec::Vec;
use core::{marker::PhantomData, time::Duration}; use core::{marker::PhantomData, time::Duration};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::net::TcpStream; use std::net::TcpStream;
@ -33,9 +33,8 @@ use crate::{
corpus::Corpus, corpus::Corpus,
events::{ events::{
llmp::{LLMP_TAG_EVENT_TO_BOTH, _LLMP_TAG_EVENT_TO_BROKER}, llmp::{LLMP_TAG_EVENT_TO_BOTH, _LLMP_TAG_EVENT_TO_BROKER},
AdaptiveSerializer, CustomBufEventResult, CustomBufHandlerFn, Event, EventConfig, AdaptiveSerializer, Event, EventConfig, EventFirer, EventManager, EventManagerHooksTuple,
EventFirer, EventManager, EventManagerHooksTuple, EventManagerId, EventProcessor, EventManagerId, EventProcessor, EventRestarter, HasEventManagerId, ProgressReporter,
EventRestarter, HasCustomBufHandlers, HasEventManagerId, ProgressReporter,
}, },
executors::{Executor, HasObservers}, executors::{Executor, HasObservers},
fuzzer::{Evaluator, EvaluatorObservers, ExecutionProcessor}, fuzzer::{Evaluator, EvaluatorObservers, ExecutionProcessor},
@ -64,8 +63,6 @@ where
hooks: EMH, hooks: EMH,
/// The LLMP client for inter process communication /// The LLMP client for inter process communication
llmp: LlmpClient<SP>, llmp: LlmpClient<SP>,
/// The custom buf handler
custom_buf_handlers: Vec<Box<CustomBufHandlerFn<S>>>,
#[cfg(feature = "llmp_compression")] #[cfg(feature = "llmp_compression")]
compressor: GzipCompressor, compressor: GzipCompressor,
/// The configuration defines this specific fuzzer. /// The configuration defines this specific fuzzer.
@ -168,7 +165,6 @@ impl<EMH> LlmpEventManagerBuilder<EMH> {
should_serialize_cnt: 0, should_serialize_cnt: 0,
time_ref, time_ref,
phantom: PhantomData, phantom: PhantomData,
custom_buf_handlers: vec![],
event_buffer: Vec::with_capacity(INITIAL_EVENT_BUFFER_SIZE), event_buffer: Vec::with_capacity(INITIAL_EVENT_BUFFER_SIZE),
}) })
} }
@ -203,7 +199,6 @@ impl<EMH> LlmpEventManagerBuilder<EMH> {
should_serialize_cnt: 0, should_serialize_cnt: 0,
time_ref, time_ref,
phantom: PhantomData, phantom: PhantomData,
custom_buf_handlers: vec![],
event_buffer: Vec::with_capacity(INITIAL_EVENT_BUFFER_SIZE), event_buffer: Vec::with_capacity(INITIAL_EVENT_BUFFER_SIZE),
}) })
} }
@ -238,7 +233,6 @@ impl<EMH> LlmpEventManagerBuilder<EMH> {
should_serialize_cnt: 0, should_serialize_cnt: 0,
time_ref, time_ref,
phantom: PhantomData, phantom: PhantomData,
custom_buf_handlers: vec![],
event_buffer: Vec::with_capacity(INITIAL_EVENT_BUFFER_SIZE), event_buffer: Vec::with_capacity(INITIAL_EVENT_BUFFER_SIZE),
}) })
} }
@ -271,7 +265,6 @@ impl<EMH> LlmpEventManagerBuilder<EMH> {
should_serialize_cnt: 0, should_serialize_cnt: 0,
time_ref, time_ref,
phantom: PhantomData, phantom: PhantomData,
custom_buf_handlers: vec![],
event_buffer: Vec::with_capacity(INITIAL_EVENT_BUFFER_SIZE), event_buffer: Vec::with_capacity(INITIAL_EVENT_BUFFER_SIZE),
}) })
} }
@ -469,13 +462,6 @@ where
} }
} }
} }
Event::CustomBuf { tag, buf } => {
for handler in &mut self.custom_buf_handlers {
if handler(state, &tag, &buf)? == CustomBufEventResult::Handled {
break;
}
}
}
Event::Stop => { Event::Stop => {
state.request_stop(); state.request_stop();
} }
@ -679,19 +665,6 @@ where
{ {
} }
impl<EMH, S, SP> HasCustomBufHandlers for LlmpEventManager<EMH, S, SP>
where
S: State,
SP: ShMemProvider,
{
fn add_custom_buf_handler(
&mut self,
handler: Box<dyn FnMut(&mut S, &str, &[u8]) -> Result<CustomBufEventResult, Error>>,
) {
self.custom_buf_handlers.push(handler);
}
}
impl<EMH, S, SP> ProgressReporter for LlmpEventManager<EMH, S, SP> impl<EMH, S, SP> ProgressReporter for LlmpEventManager<EMH, S, SP>
where where
S: State + HasExecutions + HasMetadata + HasLastReportTime, S: State + HasExecutions + HasMetadata + HasLastReportTime,

View File

@ -1,6 +1,5 @@
//! LLMP-backed event manager for scalable multi-processed fuzzing //! LLMP-backed event manager for scalable multi-processed fuzzing
use alloc::{boxed::Box, vec::Vec};
use core::{marker::PhantomData, time::Duration}; use core::{marker::PhantomData, time::Duration};
#[cfg(feature = "llmp_compression")] #[cfg(feature = "llmp_compression")]
@ -17,7 +16,7 @@ use serde::Deserialize;
use crate::{ use crate::{
corpus::Corpus, corpus::Corpus,
events::{CustomBufEventResult, CustomBufHandlerFn, Event, EventFirer}, events::{Event, EventFirer},
executors::{Executor, HasObservers}, executors::{Executor, HasObservers},
fuzzer::{EvaluatorObservers, ExecutionProcessor}, fuzzer::{EvaluatorObservers, ExecutionProcessor},
inputs::{Input, InputConverter, NopInput, NopInputConverter, UsesInput}, inputs::{Input, InputConverter, NopInput, NopInputConverter, UsesInput},
@ -96,8 +95,6 @@ where
throttle: Option<Duration>, throttle: Option<Duration>,
llmp: LlmpClient<SP>, llmp: LlmpClient<SP>,
last_sent: Duration, last_sent: Duration,
/// The custom buf handler
custom_buf_handlers: Vec<Box<CustomBufHandlerFn<S>>>,
#[cfg(feature = "llmp_compression")] #[cfg(feature = "llmp_compression")]
compressor: GzipCompressor, compressor: GzipCompressor,
converter: Option<IC>, converter: Option<IC>,
@ -165,7 +162,6 @@ impl LlmpEventConverterBuilder {
converter, converter,
converter_back, converter_back,
phantom: PhantomData, phantom: PhantomData,
custom_buf_handlers: vec![],
}) })
} }
@ -195,7 +191,6 @@ impl LlmpEventConverterBuilder {
converter, converter,
converter_back, converter_back,
phantom: PhantomData, phantom: PhantomData,
custom_buf_handlers: vec![],
}) })
} }
@ -225,7 +220,6 @@ impl LlmpEventConverterBuilder {
converter, converter,
converter_back, converter_back,
phantom: PhantomData, phantom: PhantomData,
custom_buf_handlers: vec![],
}) })
} }
} }
@ -324,14 +318,6 @@ where
} }
Ok(()) Ok(())
} }
Event::CustomBuf { tag, buf } => {
for handler in &mut self.custom_buf_handlers {
if handler(state, &tag, &buf)? == CustomBufEventResult::Handled {
break;
}
}
Ok(())
}
Event::Stop => Ok(()), Event::Stop => Ok(()),
_ => Err(Error::unknown(format!( _ => Err(Error::unknown(format!(
"Received illegal message that message should not have arrived: {:?}.", "Received illegal message that message should not have arrived: {:?}.",
@ -449,7 +435,6 @@ where
#[cfg(all(unix, feature = "std", feature = "multi_machine"))] #[cfg(all(unix, feature = "std", feature = "multi_machine"))]
node_id, node_id,
}, },
Event::CustomBuf { buf, tag } => Event::CustomBuf { buf, tag },
_ => { _ => {
return Ok(()); return Ok(());
} }
@ -506,7 +491,6 @@ where
#[cfg(all(unix, feature = "std", feature = "multi_machine"))] #[cfg(all(unix, feature = "std", feature = "multi_machine"))]
node_id, node_id,
}, },
Event::CustomBuf { buf, tag } => Event::CustomBuf { buf, tag },
_ => { _ => {
return Ok(()); return Ok(());
} }

View File

@ -3,7 +3,7 @@
//! When the target crashes, a watch process (the parent) will //! When the target crashes, a watch process (the parent) will
//! restart/refork it. //! restart/refork it.
use alloc::{boxed::Box, vec::Vec}; use alloc::vec::Vec;
use core::{ use core::{
marker::PhantomData, marker::PhantomData,
num::NonZeroUsize, num::NonZeroUsize,
@ -34,10 +34,10 @@ use crate::events::EVENTMGR_SIGHANDLER_STATE;
use crate::{ use crate::{
corpus::Corpus, corpus::Corpus,
events::{ events::{
launcher::ClientDescription, AdaptiveSerializer, CustomBufEventResult, Event, EventConfig, launcher::ClientDescription, AdaptiveSerializer, Event, EventConfig, EventFirer,
EventFirer, EventManager, EventManagerHooksTuple, EventManagerId, EventProcessor, EventManager, EventManagerHooksTuple, EventManagerId, EventProcessor, EventRestarter,
EventRestarter, HasCustomBufHandlers, HasEventManagerId, LlmpEventManager, HasEventManagerId, LlmpEventManager, LlmpShouldSaveState, ProgressReporter,
LlmpShouldSaveState, ProgressReporter, StdLlmpEventHook, StdLlmpEventHook,
}, },
executors::{Executor, HasObservers}, executors::{Executor, HasObservers},
fuzzer::{Evaluator, EvaluatorObservers, ExecutionProcessor}, fuzzer::{Evaluator, EvaluatorObservers, ExecutionProcessor},
@ -246,19 +246,6 @@ where
} }
} }
impl<EMH, S, SP> HasCustomBufHandlers for LlmpRestartingEventManager<EMH, S, SP>
where
S: State,
SP: ShMemProvider,
{
fn add_custom_buf_handler(
&mut self,
handler: Box<dyn FnMut(&mut S, &str, &[u8]) -> Result<CustomBufEventResult, Error>>,
) {
self.llmp_mgr.add_custom_buf_handler(handler);
}
}
/// The llmp connection from the actual fuzzer to the process supervising it /// The llmp connection from the actual fuzzer to the process supervising it
const _ENV_FUZZER_SENDER: &str = "_AFL_ENV_FUZZER_SENDER"; const _ENV_FUZZER_SENDER: &str = "_AFL_ENV_FUZZER_SENDER";
const _ENV_FUZZER_RECEIVER: &str = "_AFL_ENV_FUZZER_RECEIVER"; const _ENV_FUZZER_RECEIVER: &str = "_AFL_ENV_FUZZER_RECEIVER";

View File

@ -19,7 +19,9 @@ pub use llmp::*;
pub mod tcp; pub mod tcp;
pub mod broker_hooks; pub mod broker_hooks;
use alloc::{borrow::Cow, boxed::Box, string::String, vec::Vec}; #[cfg(feature = "introspection")]
use alloc::boxed::Box;
use alloc::{borrow::Cow, string::String, vec::Vec};
use core::{ use core::{
fmt, fmt,
hash::{BuildHasher, Hasher}, hash::{BuildHasher, Hasher},
@ -154,15 +156,6 @@ impl fmt::Display for LogSeverity {
} }
} }
/// The result of a custom buf handler added using [`HasCustomBufHandlers::add_custom_buf_handler`]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CustomBufEventResult {
/// Exit early from event handling
Handled,
/// Call the next handler, if available
Next,
}
/// Indicate if an event worked or not /// Indicate if an event worked or not
#[derive(Serialize, Deserialize, Debug, Copy, Clone)] #[derive(Serialize, Deserialize, Debug, Copy, Clone)]
pub enum BrokerEventResult { pub enum BrokerEventResult {
@ -337,13 +330,6 @@ where
/// `PhantomData` /// `PhantomData`
phantom: PhantomData<I>, phantom: PhantomData<I>,
}, },
/// Sends a custom buffer to other clients
CustomBuf {
/// The buffer
buf: Vec<u8>,
/// Tag of this buffer
tag: String,
},
/// Exit gracefully /// Exit gracefully
Stop, Stop,
/*/// A custom type /*/// A custom type
@ -367,7 +353,6 @@ where
Event::UpdatePerfMonitor { .. } => "PerfMonitor", Event::UpdatePerfMonitor { .. } => "PerfMonitor",
Event::Objective { .. } => "Objective", Event::Objective { .. } => "Objective",
Event::Log { .. } => "Log", Event::Log { .. } => "Log",
Event::CustomBuf { .. } => "CustomBuf",
/*Event::Custom { /*Event::Custom {
sender_id: _, /*custom_event} => custom_event.name()*/ sender_id: _, /*custom_event} => custom_event.name()*/
} => "todo",*/ } => "todo",*/
@ -387,7 +372,6 @@ where
Event::UpdatePerfMonitor { .. } => Cow::Borrowed("PerfMonitor"), Event::UpdatePerfMonitor { .. } => Cow::Borrowed("PerfMonitor"),
Event::Objective { .. } => Cow::Borrowed("Objective"), Event::Objective { .. } => Cow::Borrowed("Objective"),
Event::Log { .. } => Cow::Borrowed("Log"), Event::Log { .. } => Cow::Borrowed("Log"),
Event::CustomBuf { .. } => Cow::Borrowed("CustomBuf"),
Event::Stop => Cow::Borrowed("Stop"), Event::Stop => Cow::Borrowed("Stop"),
/*Event::Custom { /*Event::Custom {
sender_id: _, /*custom_event} => custom_event.name()*/ sender_id: _, /*custom_event} => custom_event.name()*/
@ -598,15 +582,6 @@ where
{ {
} }
/// The handler function for custom buffers exchanged via [`EventManager`]
type CustomBufHandlerFn<S> = dyn FnMut(&mut S, &str, &[u8]) -> Result<CustomBufEventResult, Error>;
/// Supports custom buf handlers to handle `CustomBuf` events.
pub trait HasCustomBufHandlers: UsesState {
/// Adds a custom buffer handler that will run for each incoming `CustomBuf` event.
fn add_custom_buf_handler(&mut self, handler: Box<CustomBufHandlerFn<Self::State>>);
}
/// An eventmgr for tests, and as placeholder if you really don't need an event manager. /// An eventmgr for tests, and as placeholder if you really don't need an event manager.
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub struct NopEventManager<S> { pub struct NopEventManager<S> {
@ -678,19 +653,6 @@ impl<E, S, Z> EventManager<E, Z> for NopEventManager<S> where
{ {
} }
impl<S> HasCustomBufHandlers for NopEventManager<S>
where
S: State,
{
fn add_custom_buf_handler(
&mut self,
_handler: Box<
dyn FnMut(&mut Self::State, &str, &[u8]) -> Result<CustomBufEventResult, Error>,
>,
) {
}
}
impl<S> ProgressReporter for NopEventManager<S> where impl<S> ProgressReporter for NopEventManager<S> where
S: State + HasExecutions + HasLastReportTime + HasMetadata S: State + HasExecutions + HasLastReportTime + HasMetadata
{ {
@ -815,22 +777,6 @@ where
{ {
} }
impl<EM, M> HasCustomBufHandlers for MonitorTypedEventManager<EM, M>
where
Self: UsesState,
EM: HasCustomBufHandlers<State = Self::State>,
{
#[inline]
fn add_custom_buf_handler(
&mut self,
handler: Box<
dyn FnMut(&mut Self::State, &str, &[u8]) -> Result<CustomBufEventResult, Error>,
>,
) {
self.inner.add_custom_buf_handler(handler);
}
}
impl<EM, M> ProgressReporter for MonitorTypedEventManager<EM, M> impl<EM, M> ProgressReporter for MonitorTypedEventManager<EM, M>
where where
Self: UsesState, Self: UsesState,

View File

@ -1,6 +1,6 @@
//! A very simple event manager, that just supports log outputs, but no multiprocessing //! A very simple event manager, that just supports log outputs, but no multiprocessing
use alloc::{boxed::Box, vec::Vec}; use alloc::vec::Vec;
use core::{fmt::Debug, marker::PhantomData}; use core::{fmt::Debug, marker::PhantomData};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use core::{ use core::{
@ -20,7 +20,7 @@ use libafl_bolts::{os::CTRL_C_EXIT, shmem::ShMemProvider, staterestore::StateRes
#[cfg(feature = "std")] #[cfg(feature = "std")]
use serde::{de::DeserializeOwned, Serialize}; use serde::{de::DeserializeOwned, Serialize};
use super::{CustomBufEventResult, CustomBufHandlerFn, HasCustomBufHandlers, ProgressReporter}; use super::ProgressReporter;
#[cfg(all(unix, feature = "std", not(miri)))] #[cfg(all(unix, feature = "std", not(miri)))]
use crate::events::EVENTMGR_SIGHANDLER_STATE; use crate::events::EVENTMGR_SIGHANDLER_STATE;
use crate::{ use crate::{
@ -54,8 +54,6 @@ where
monitor: MT, monitor: MT,
/// The events that happened since the last `handle_in_broker` /// The events that happened since the last `handle_in_broker`
events: Vec<Event<S::Input>>, events: Vec<Event<S::Input>>,
/// The custom buf handler
custom_buf_handlers: Vec<Box<CustomBufHandlerFn<S>>>,
phantom: PhantomData<S>, phantom: PhantomData<S>,
} }
@ -122,7 +120,7 @@ where
) -> Result<usize, Error> { ) -> Result<usize, Error> {
let count = self.events.len(); let count = self.events.len();
while let Some(event) = self.events.pop() { while let Some(event) = self.events.pop() {
self.handle_in_client(state, event)?; self.handle_in_client(state, &event)?;
} }
Ok(count) Ok(count)
} }
@ -139,22 +137,6 @@ where
{ {
} }
impl<MT, S> HasCustomBufHandlers for SimpleEventManager<MT, S>
where
MT: Monitor, //CE: CustomEvent<I, OT>,
S: State,
{
/// Adds a custom buffer handler that will run for each incoming `CustomBuf` event.
fn add_custom_buf_handler(
&mut self,
handler: Box<
dyn FnMut(&mut Self::State, &str, &[u8]) -> Result<CustomBufEventResult, Error>,
>,
) {
self.custom_buf_handlers.push(handler);
}
}
impl<MT, S> ProgressReporter for SimpleEventManager<MT, S> impl<MT, S> ProgressReporter for SimpleEventManager<MT, S>
where where
MT: Monitor, MT: Monitor,
@ -194,7 +176,6 @@ where
Self { Self {
monitor, monitor,
events: vec![], events: vec![],
custom_buf_handlers: vec![],
phantom: PhantomData, phantom: PhantomData,
} }
} }
@ -267,20 +248,14 @@ where
log::log!((*severity_level).into(), "{message}"); log::log!((*severity_level).into(), "{message}");
Ok(BrokerEventResult::Handled) Ok(BrokerEventResult::Handled)
} }
Event::CustomBuf { .. } => Ok(BrokerEventResult::Forward),
Event::Stop => Ok(BrokerEventResult::Forward), Event::Stop => Ok(BrokerEventResult::Forward),
} }
} }
// Handle arriving events in the client // Handle arriving events in the client
fn handle_in_client(&mut self, state: &mut S, event: Event<S::Input>) -> Result<(), Error> { #[allow(clippy::unused_self)]
fn handle_in_client(&mut self, state: &mut S, event: &Event<S::Input>) -> Result<(), Error> {
match event { match event {
Event::CustomBuf { buf, tag } => {
for handler in &mut self.custom_buf_handlers {
handler(state, &tag, &buf)?;
}
Ok(())
}
Event::Stop => { Event::Stop => {
state.request_stop(); state.request_stop();
Ok(()) Ok(())
@ -394,21 +369,6 @@ where
{ {
} }
#[cfg(feature = "std")]
impl<MT, S, SP> HasCustomBufHandlers for SimpleRestartingEventManager<MT, S, SP>
where
MT: Monitor,
S: State,
SP: ShMemProvider,
{
fn add_custom_buf_handler(
&mut self,
handler: Box<dyn FnMut(&mut S, &str, &[u8]) -> Result<CustomBufEventResult, Error>>,
) {
self.simple_event_mgr.add_custom_buf_handler(handler);
}
}
#[cfg(feature = "std")] #[cfg(feature = "std")]
impl<MT, S, SP> ProgressReporter for SimpleRestartingEventManager<MT, S, SP> impl<MT, S, SP> ProgressReporter for SimpleRestartingEventManager<MT, S, SP>
where where

View File

@ -1,6 +1,6 @@
//! TCP-backed event manager for scalable multi-processed fuzzing //! TCP-backed event manager for scalable multi-processed fuzzing
use alloc::{boxed::Box, vec::Vec}; use alloc::vec::Vec;
use core::{ use core::{
marker::PhantomData, marker::PhantomData,
num::NonZeroUsize, num::NonZeroUsize,
@ -38,15 +38,13 @@ use tokio::{
}; };
use typed_builder::TypedBuilder; use typed_builder::TypedBuilder;
use super::{CustomBufEventResult, CustomBufHandlerFn};
#[cfg(all(unix, not(miri)))] #[cfg(all(unix, not(miri)))]
use crate::events::EVENTMGR_SIGHANDLER_STATE; use crate::events::EVENTMGR_SIGHANDLER_STATE;
use crate::{ use crate::{
corpus::Corpus, corpus::Corpus,
events::{ events::{
BrokerEventResult, Event, EventConfig, EventFirer, EventManager, EventManagerHooksTuple, BrokerEventResult, Event, EventConfig, EventFirer, EventManager, EventManagerHooksTuple,
EventManagerId, EventProcessor, EventRestarter, HasCustomBufHandlers, HasEventManagerId, EventManagerId, EventProcessor, EventRestarter, HasEventManagerId, ProgressReporter,
ProgressReporter,
}, },
executors::{Executor, HasObservers}, executors::{Executor, HasObservers},
fuzzer::{EvaluatorObservers, ExecutionProcessor}, fuzzer::{EvaluatorObservers, ExecutionProcessor},
@ -399,7 +397,7 @@ where
log::log!((*severity_level).into(), "{message}"); log::log!((*severity_level).into(), "{message}");
Ok(BrokerEventResult::Handled) Ok(BrokerEventResult::Handled)
} }
Event::CustomBuf { .. } | Event::Stop => Ok(BrokerEventResult::Forward), Event::Stop => Ok(BrokerEventResult::Forward),
//_ => Ok(BrokerEventResult::Forward), //_ => Ok(BrokerEventResult::Forward),
} }
} }
@ -420,8 +418,6 @@ where
tcp: TcpStream, tcp: TcpStream,
/// Our `CientId` /// Our `CientId`
client_id: ClientId, client_id: ClientId,
/// The custom buf handler
custom_buf_handlers: Vec<Box<CustomBufHandlerFn<S>>>,
#[cfg(feature = "tcp_compression")] #[cfg(feature = "tcp_compression")]
compressor: GzipCompressor, compressor: GzipCompressor,
/// The configuration defines this specific fuzzer. /// The configuration defines this specific fuzzer.
@ -519,7 +515,6 @@ where
compressor: GzipCompressor::new(), compressor: GzipCompressor::new(),
configuration, configuration,
phantom: PhantomData, phantom: PhantomData,
custom_buf_handlers: vec![],
}) })
} }
@ -643,13 +638,6 @@ where
log::info!("Added received Testcase as item #{item}"); log::info!("Added received Testcase as item #{item}");
} }
} }
Event::CustomBuf { tag, buf } => {
for handler in &mut self.custom_buf_handlers {
if handler(state, &tag, &buf)? == CustomBufEventResult::Handled {
break;
}
}
}
Event::Stop => { Event::Stop => {
state.request_stop(); state.request_stop();
} }
@ -826,19 +814,6 @@ where
{ {
} }
impl<EMH, S> HasCustomBufHandlers for TcpEventManager<EMH, S>
where
EMH: EventManagerHooksTuple<S>,
S: State,
{
fn add_custom_buf_handler(
&mut self,
handler: Box<dyn FnMut(&mut S, &str, &[u8]) -> Result<CustomBufEventResult, Error>>,
) {
self.custom_buf_handlers.push(handler);
}
}
impl<EMH, S> ProgressReporter for TcpEventManager<EMH, S> impl<EMH, S> ProgressReporter for TcpEventManager<EMH, S>
where where
EMH: EventManagerHooksTuple<S>, EMH: EventManagerHooksTuple<S>,