diff --git a/libafl/src/feedbacks/mod.rs b/libafl/src/feedbacks/mod.rs index c997ebabb3..4ed091b2e8 100644 --- a/libafl/src/feedbacks/mod.rs +++ b/libafl/src/feedbacks/mod.rs @@ -364,37 +364,6 @@ where self(ctx) } } - -/// A feedback factory which merely invokes `::default()` for the feedback type provided -#[derive(Default, Debug, Copy, Clone)] -pub struct DefaultFeedbackFactory -where - F: Default, -{ - phantom: PhantomData, -} - -impl DefaultFeedbackFactory -where - F: Default, -{ - /// Create the feedback factory - #[must_use] - pub fn new() -> Self { - Self::default() - } -} - -impl FeedbackFactory for DefaultFeedbackFactory -where - F: Feedback + Default, - S: State, -{ - fn create_feedback(&self, _ctx: &T) -> F { - F::default() - } -} - /// Eager `OR` combination of two feedbacks #[derive(Debug, Clone)] pub struct LogicEagerOr {} @@ -820,7 +789,7 @@ where /// A [`CrashFeedback`] reports as interesting if the target crashed. #[derive(Serialize, Deserialize, Clone, Debug)] -pub struct CrashFeedback {} +pub struct CrashFeedback; impl Feedback for CrashFeedback where @@ -859,7 +828,7 @@ impl CrashFeedback { /// Creates a new [`CrashFeedback`] #[must_use] pub fn new() -> Self { - Self {} + Self } } @@ -877,7 +846,7 @@ impl FeedbackFactory for CrashFeedback { /// A [`TimeoutFeedback`] reduces the timeout value of a run. #[derive(Serialize, Deserialize, Clone, Debug)] -pub struct TimeoutFeedback {} +pub struct TimeoutFeedback; impl Feedback for TimeoutFeedback where @@ -916,7 +885,7 @@ impl TimeoutFeedback { /// Returns a new [`TimeoutFeedback`]. #[must_use] pub fn new() -> Self { - Self {} + Self } } @@ -927,7 +896,65 @@ impl Default for TimeoutFeedback { } /// A feedback factory for timeout feedbacks -pub type TimeoutFeedbackFactory = DefaultFeedbackFactory; +impl FeedbackFactory for TimeoutFeedback { + fn create_feedback(&self, _ctx: &T) -> TimeoutFeedback { + TimeoutFeedback::new() + } +} + +/// A [`DiffExitKindFeedback`] checks if there is a difference in the [`crate::executors::ExitKind`]s in a [`crate::executors::DiffExecutor`]. +#[derive(Serialize, Deserialize, Clone, Debug)] +pub struct DiffExitKindFeedback; + +impl Feedback for DiffExitKindFeedback +where + S: State, +{ + #[allow(clippy::wrong_self_convention)] + fn is_interesting( + &mut self, + _state: &mut S, + _manager: &mut EM, + _input: &S::Input, + _observers: &OT, + exit_kind: &ExitKind, + ) -> Result + where + EM: EventFirer, + OT: ObserversTuple, + { + Ok(matches!(exit_kind, ExitKind::Diff { .. })) + } +} + +impl Named for DiffExitKindFeedback { + #[inline] + fn name(&self) -> &Cow<'static, str> { + static NAME: Cow<'static, str> = Cow::Borrowed("DiffExitKindFeedback"); + &NAME + } +} + +impl DiffExitKindFeedback { + /// Returns a new [`DiffExitKindFeedback`]. + #[must_use] + pub fn new() -> Self { + Self + } +} + +impl Default for DiffExitKindFeedback { + fn default() -> Self { + Self::new() + } +} + +/// A feedback factory for diff exit kind feedbacks +impl FeedbackFactory for DiffExitKindFeedback { + fn create_feedback(&self, _ctx: &T) -> DiffExitKindFeedback { + DiffExitKindFeedback::new() + } +} /// Nop feedback that annotates execution time in the new testcase, if any /// for this Feedback, the testcase is never interesting (use with an OR). diff --git a/libafl_libfuzzer/libafl_libfuzzer_runtime/src/tmin.rs b/libafl_libfuzzer/libafl_libfuzzer_runtime/src/tmin.rs index 4a2bbae991..82b8398871 100644 --- a/libafl_libfuzzer/libafl_libfuzzer_runtime/src/tmin.rs +++ b/libafl_libfuzzer/libafl_libfuzzer_runtime/src/tmin.rs @@ -7,7 +7,7 @@ use libafl::{ corpus::{Corpus, HasTestcase, InMemoryCorpus, Testcase}, events::SimpleEventManager, executors::{inprocess_fork::InProcessForkExecutor, ExitKind}, - feedbacks::{CrashFeedback, TimeoutFeedbackFactory}, + feedbacks::{CrashFeedback, TimeoutFeedback}, inputs::{BytesInput, HasMutatorBytes, HasTargetBytes}, mutators::{havoc_mutations_no_crossover, Mutator, StdScheduledMutator}, schedulers::QueueScheduler, @@ -93,7 +93,7 @@ fn minimize_crash_with_mutator>( fuzzer.fuzz_one(&mut stages, &mut executor, &mut state, &mut mgr)?; } ExitKind::Timeout => { - let factory = TimeoutFeedbackFactory::default(); + let factory = TimeoutFeedback; let tmin = StdTMinMutationalStage::new( mutator, factory,