Add FeedbackFactory implementations for CrashFeedback, CombinedFeedback and DiffFeedback. (#2060)

* Add FeedbackFactory implementations for CrashFeedback, CombinedFeedback and DiffFeedback

* remove redundant type CrashFeedbackFactory
This commit is contained in:
Josef Haider 2024-04-23 15:48:52 +02:00 committed by GitHub
parent e1b8c9b5d8
commit d34965192d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 45 additions and 6 deletions

View File

@ -124,7 +124,7 @@ pub fn main() -> Result<(), Error> {
let minimizer = StdScheduledMutator::new(havoc_mutations());
let mut stages = tuple_list!(StdTMinMutationalStage::new(
minimizer,
CrashFeedbackFactory::default(),
CrashFeedback::new(),
1 << 10
));

View File

@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
use crate::{
events::EventFirer,
executors::ExitKind,
feedbacks::Feedback,
feedbacks::{Feedback, FeedbackFactory},
inputs::Input,
observers::{Observer, ObserversTuple},
state::State,
@ -89,6 +89,26 @@ where
}
}
impl<F, I, O1, O2, S, T> FeedbackFactory<DiffFeedback<F, I, O1, O2, S>, S, T>
for DiffFeedback<F, I, O1, O2, S>
where
F: FnMut(&O1, &O2) -> DiffResult + Clone,
I: Input,
O1: Observer<S> + Named,
O2: Observer<S> + Named,
S: HasMetadata + State<Input = I>,
{
fn create_feedback(&self, _ctx: &T) -> DiffFeedback<F, I, O1, O2, S> {
Self {
name: self.name.clone(),
o1_name: self.o1_name.clone(),
o2_name: self.o2_name.clone(),
compare_fn: self.compare_fn.clone(),
phantomm: self.phantomm,
}
}
}
impl<F, I, O1, O2, S> Named for DiffFeedback<F, I, O1, O2, S>
where
F: FnMut(&O1, &O2) -> DiffResult,

View File

@ -276,6 +276,22 @@ where
}
}
impl<A, B, FL, S, T> FeedbackFactory<CombinedFeedback<A, B, FL, S>, S, T>
for CombinedFeedback<A, B, FL, S>
where
A: Feedback<S> + FeedbackFactory<A, S, T>,
B: Feedback<S> + FeedbackFactory<B, S, T>,
FL: FeedbackLogic<A, B, S>,
S: State,
{
fn create_feedback(&self, ctx: &T) -> CombinedFeedback<A, B, FL, S> {
CombinedFeedback::new(
self.first.create_feedback(ctx),
self.second.create_feedback(ctx),
)
}
}
/// Logical combination of two feedbacks
pub trait FeedbackLogic<A, B, S>: 'static
where
@ -842,8 +858,11 @@ impl Default for CrashFeedback {
}
}
/// A feedback factory for crash feedbacks
pub type CrashFeedbackFactory = DefaultFeedbackFactory<CrashFeedback>;
impl<S: State, T> FeedbackFactory<CrashFeedback, S, T> for CrashFeedback {
fn create_feedback(&self, _ctx: &T) -> CrashFeedback {
CrashFeedback::new()
}
}
/// A [`TimeoutFeedback`] reduces the timeout value of a run.
#[derive(Serialize, Deserialize, Clone, Debug)]

View File

@ -7,7 +7,7 @@ use libafl::{
corpus::{Corpus, HasTestcase, InMemoryCorpus, Testcase},
events::SimpleEventManager,
executors::{inprocess_fork::InProcessForkExecutor, ExitKind},
feedbacks::{CrashFeedbackFactory, TimeoutFeedbackFactory},
feedbacks::{CrashFeedback, TimeoutFeedbackFactory},
inputs::{BytesInput, HasBytesVec, HasTargetBytes},
mutators::{havoc_mutations_no_crossover, Mutator, StdScheduledMutator},
schedulers::QueueScheduler,
@ -79,7 +79,7 @@ fn minimize_crash_with_mutator<M: Mutator<BytesInput, TMinState>>(
match exit_kind {
ExitKind::Crash => {
let factory = CrashFeedbackFactory::default();
let factory = CrashFeedback::new();
let tmin = StdTMinMutationalStage::new(
mutator,
factory,