Skip to content

Commit

Permalink
libafl-fuzz: add IndexesLenMinTimeScheduler back (AFLplusplus#2426)
Browse files Browse the repository at this point in the history
  • Loading branch information
R9295 authored Jul 18, 2024
1 parent 78a30c4 commit c22a62c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
10 changes: 8 additions & 2 deletions fuzzers/libafl-fuzz/src/fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ use libafl::{
scheduled::havoc_mutations, tokens_mutations, AFLppRedQueen, StdScheduledMutator, Tokens,
},
observers::{CanTrack, HitcountsMapObserver, StdMapObserver, TimeObserver},
schedulers::{powersched::PowerSchedule, QueueScheduler, StdWeightedScheduler},
schedulers::{
powersched::PowerSchedule, IndexesLenTimeMinimizerScheduler, QueueScheduler,
StdWeightedScheduler,
},
stages::{
mutational::MultiMutationalStage, CalibrationStage, ColorizationStage, IfStage,
StagesTuple, StdMutationalStage, StdPowerMutationalStage, SyncFromDiskStage,
Expand Down Expand Up @@ -183,7 +186,10 @@ where
weighted_scheduler = weighted_scheduler.cycling_scheduler();
}
// TODO: Go back to IndexesLenTimeMinimizerScheduler once AflScheduler is implemented for it.
scheduler = SupportedSchedulers::Weighted(weighted_scheduler, PhantomData);
scheduler = SupportedSchedulers::Weighted(
IndexesLenTimeMinimizerScheduler::new(&edges_observer, weighted_scheduler),
PhantomData,
);
}

// Create our Fuzzer
Expand Down
36 changes: 23 additions & 13 deletions fuzzers/libafl-fuzz/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,33 @@ use std::marker::PhantomData;
use libafl::{
corpus::{CorpusId, HasTestcase, Testcase},
inputs::UsesInput,
observers::ObserversTuple,
schedulers::{HasQueueCycles, RemovableScheduler, Scheduler},
observers::{CanTrack, ObserversTuple},
schedulers::{HasQueueCycles, MinimizerScheduler, RemovableScheduler, Scheduler, TestcaseScore},
state::{HasCorpus, HasRand, State, UsesState},
Error, HasMetadata,
};
use libafl_bolts::{serdeany::SerdeAny, AsIter, HasRefCnt};

pub enum SupportedSchedulers<S, Q, W> {
Queue(Q, PhantomData<(S, Q, W)>),
Weighted(W, PhantomData<(S, Q, W)>),
pub enum SupportedSchedulers<S, Q, CS, F, M, O> {
Queue(Q, PhantomData<(S, Q, CS, F, M, O)>),
Weighted(MinimizerScheduler<CS, F, M, O>, PhantomData<(S, Q, CS, F, M, O)>),
}

impl<S, Q, W> UsesState for SupportedSchedulers<S, Q, W>
impl<S, Q, CS, F, M, O> UsesState for SupportedSchedulers<S, Q, CS, F, M, O>
where
S: State + HasRand + HasCorpus + HasMetadata + HasTestcase,
{
type State = S;
}

impl<S, Q, W> RemovableScheduler for SupportedSchedulers<S, Q, W>
impl<S, Q, CS, F, M, O> RemovableScheduler for SupportedSchedulers<S, Q, CS, F, M, O>
where
S: UsesInput + HasTestcase + HasMetadata + HasCorpus + HasRand + State,
Q: Scheduler<State = S> + RemovableScheduler,
W: Scheduler<State = S> + RemovableScheduler,
CS: RemovableScheduler<State = S>,
M: for<'a> AsIter<'a, Item = usize> + SerdeAny + HasRefCnt,
O: CanTrack,
F: TestcaseScore<S>,
{
fn on_remove(
&mut self,
Expand All @@ -52,11 +56,14 @@ where
}
}

impl<S, Q, W> Scheduler for SupportedSchedulers<S, Q, W>
impl<S, Q, CS, F, M, O> Scheduler for SupportedSchedulers<S, Q, CS, F, M, O>
where
S: UsesInput + HasTestcase + HasMetadata + HasCorpus + HasRand + State,
Q: Scheduler<State = S>,
W: Scheduler<State = S>,
CS: Scheduler<State = S>,
M: for<'a> AsIter<'a, Item = usize> + SerdeAny + HasRefCnt,
O: CanTrack,
F: TestcaseScore<S>
{
fn on_add(&mut self, state: &mut Self::State, id: CorpusId) -> Result<(), Error> {
match self {
Expand Down Expand Up @@ -99,16 +106,19 @@ where
}
}

impl<S, Q, W> HasQueueCycles for SupportedSchedulers<S, Q, W>
impl<S, Q, CS, F, M, O> HasQueueCycles for SupportedSchedulers<S, Q, CS, F, M, O>
where
S: UsesInput + HasTestcase + HasMetadata + HasCorpus + HasRand + State,
Q: Scheduler<State = S> + HasQueueCycles,
W: Scheduler<State = S> + HasQueueCycles,
CS: Scheduler<State = S> + HasQueueCycles,
O: CanTrack,
M: for<'a> AsIter<'a, Item = usize> + SerdeAny + HasRefCnt,
F: TestcaseScore<S>
{
fn queue_cycles(&self) -> u64 {
match self {
Self::Queue(queue, _) => queue.queue_cycles(),
Self::Weighted(weighted, _) => weighted.queue_cycles(),
Self::Weighted(weighted, _) => weighted.base().queue_cycles(),
}
}
}

0 comments on commit c22a62c

Please sign in to comment.