Skip to content

Commit

Permalink
80%done
Browse files Browse the repository at this point in the history
  • Loading branch information
tokatoka committed Jan 11, 2025
1 parent 2cf65b9 commit 052b733
Show file tree
Hide file tree
Showing 21 changed files with 106 additions and 175 deletions.
2 changes: 0 additions & 2 deletions libafl/src/corpus/minimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ pub type StdCorpusMinimizer<C, E, O, T> = MapCorpusMinimizer<C, E, O, T, LenTime

impl<C, E, O, T, TS> MapCorpusMinimizer<C, E, O, T, TS>
where
E: UsesState,
E::State: HasCorpus + HasMetadata,
TS: TestcaseScore<E::State>,
C: Named,
Expand All @@ -55,7 +54,6 @@ where

impl<C, E, O, T, TS> MapCorpusMinimizer<C, E, O, T, TS>
where
E: UsesState,
for<'a> O: MapObserver<Entry = T> + AsIter<'a, Item = T>,
C: AsRef<O>,
E::State: HasMetadata + HasCorpus + HasExecutions,
Expand Down
8 changes: 4 additions & 4 deletions libafl/src/events/centralized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ impl<E, EM, EMH, S, SP, Z> EventProcessor<E, Z> for CentralizedEventManager<EM,
where
EM: AdaptiveSerializer + EventProcessor<E, Z> + EventFirer<State = S> + HasEventManagerId,
EMH: EventManagerHooksTuple<S>,
E: HasObservers + Executor<Self, Z, State = Self::State>,
E: HasObservers + Executor<Self, <S::Corpus as Corpus>::Input, S, Z>,
E::Observers:
ObserversTuple<<Self as UsesInput>::Input, <Self as UsesState>::State> + Serialize,
for<'a> E::Observers: Deserialize<'a>,
Expand Down Expand Up @@ -402,7 +402,7 @@ where

impl<E, EM, EMH, S, SP, Z> EventManager<E, Z> for CentralizedEventManager<EM, EMH, S, SP>
where
E: HasObservers + Executor<Self, Z, State = Self::State>,
E: HasObservers + Executor<Self, <S::Corpus as Corpus>::Input, S, Z>,
E::Observers:
ObserversTuple<<Self as UsesInput>::Input, <Self as UsesState>::State> + Serialize,
for<'a> E::Observers: Deserialize<'a>,
Expand Down Expand Up @@ -532,7 +532,7 @@ where
executor: &mut E,
) -> Result<usize, Error>
where
E: Executor<Self, Z, State = <Self as UsesState>::State> + HasObservers,
E: Executor<Self, <S::Corpus as Corpus>::Input, S, Z> + HasObservers,
E::Observers:
ObserversTuple<<Self as UsesInput>::Input, <Self as UsesState>::State> + Serialize,
<Self as UsesState>::State: UsesInput + HasExecutions + HasMetadata,
Expand Down Expand Up @@ -582,7 +582,7 @@ where
event: Event<<<Self as UsesState>::State as UsesInput>::Input>,
) -> Result<(), Error>
where
E: Executor<Self, Z, State = <Self as UsesState>::State> + HasObservers,
E: Executor<Self, <S::Corpus as Corpus>::Input, S, Z> + HasObservers,
E::Observers:
ObserversTuple<<Self as UsesInput>::Input, <Self as UsesState>::State> + Serialize,
<Self as UsesState>::State: UsesInput + HasExecutions + HasMetadata,
Expand Down
6 changes: 3 additions & 3 deletions libafl/src/events/llmp/mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ where
event: Event<S::Input>,
) -> Result<(), Error>
where
E: Executor<Self, Z, State = S> + HasObservers,
E: Executor<Self, <S::Corpus as Corpus>::Input, S, Z> + HasObservers,
E::Observers: ObserversTuple<S::Input, S> + Serialize,
for<'a> E::Observers: Deserialize<'a>,
Z: ExecutionProcessor<Self, <S::Corpus as Corpus>::Input, E::Observers, S>
Expand Down Expand Up @@ -608,7 +608,7 @@ where
S: State + HasExecutions + HasMetadata + HasImported + HasCorpus,
S::Corpus: Corpus<Input = S::Input>,
SP: ShMemProvider,
E: HasObservers + Executor<Self, Z, State = S>,
E: HasObservers + Executor<Self, <S::Corpus as Corpus>::Input, S, Z>,
E::Observers: ObserversTuple<S::Input, S> + Serialize,
for<'a> E::Observers: Deserialize<'a>,
Z: ExecutionProcessor<Self, <S::Corpus as Corpus>::Input, E::Observers, S>
Expand Down Expand Up @@ -666,7 +666,7 @@ where

impl<E, EMH, S, SP, Z> EventManager<E, Z> for LlmpEventManager<EMH, S, SP>
where
E: HasObservers + Executor<Self, Z, State = S>,
E: HasObservers + Executor<Self, <S::Corpus as Corpus>::Input, S, Z>,
E::Observers: ObserversTuple<S::Input, S> + Serialize,
for<'a> E::Observers: Deserialize<'a>,
EMH: EventManagerHooksTuple<S>,
Expand Down
4 changes: 2 additions & 2 deletions libafl/src/events/llmp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ where
event: Event<DI>,
) -> Result<(), Error>
where
E: Executor<EM, Z, State = S> + HasObservers,
E: Executor<EM, <S::Corpus as Corpus>::Input, S, Z> + HasObservers,
EM: UsesState<State = S> + EventFirer,
S::Corpus: Corpus<Input = S::Input>,
for<'a> E::Observers: Deserialize<'a>,
Expand Down Expand Up @@ -349,7 +349,7 @@ where
manager: &mut EM,
) -> Result<usize, Error>
where
E: Executor<EM, Z, State = S> + HasObservers,
E: Executor<EM, <S::Corpus as Corpus>::Input, S, Z> + HasObservers,
EM: UsesState<State = S> + EventFirer,
S::Corpus: Corpus<Input = S::Input>,
for<'a> E::Observers: Deserialize<'a>,
Expand Down
4 changes: 2 additions & 2 deletions libafl/src/events/llmp/restarting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ where

impl<E, EMH, S, SP, Z> EventProcessor<E, Z> for LlmpRestartingEventManager<EMH, S, SP>
where
E: HasObservers + Executor<LlmpEventManager<EMH, S, SP>, Z, State = S>,
E: HasObservers + Executor<LlmpEventManager<EMH, S, SP>, <S::Corpus as Corpus>::Input, S, Z>,
E::Observers: ObserversTuple<S::Input, S> + Serialize,
for<'a> E::Observers: Deserialize<'a>,
EMH: EventManagerHooksTuple<S>,
Expand Down Expand Up @@ -219,7 +219,7 @@ where

impl<E, EMH, S, SP, Z> EventManager<E, Z> for LlmpRestartingEventManager<EMH, S, SP>
where
E: HasObservers + Executor<LlmpEventManager<EMH, S, SP>, Z, State = S>,
E: HasObservers + Executor<LlmpEventManager<EMH, S, SP>, <S::Corpus as Corpus>::Input, S, Z>,
E::Observers: ObserversTuple<S::Input, S> + Serialize,
for<'a> E::Observers: Deserialize<'a>,
EMH: EventManagerHooksTuple<S>,
Expand Down
15 changes: 9 additions & 6 deletions libafl/src/executors/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ impl CommandExecutorBuilder {
/// # Example
/// ```
/// use std::{io::Write, process::{Stdio, Command, Child}, time::Duration};
/// use libafl::{Error, inputs::{BytesInput, HasTargetBytes, Input, UsesInput}, executors::{Executor, command::CommandConfigurator}, state::{UsesState, HasExecutions}};
/// use libafl::{Error, corpus::Corpus, inputs::{BytesInput, HasTargetBytes, Input, UsesInput}, executors::{Executor, command::CommandConfigurator}, state::{HasCorpus, UsesState, HasExecutions}};
/// use libafl_bolts::AsSlice;
/// #[derive(Debug)]
/// struct MyExecutor;
Expand Down Expand Up @@ -775,10 +775,12 @@ impl CommandExecutorBuilder {
/// }
/// }
///
/// fn make_executor<EM, Z>() -> impl Executor<EM, Z>
/// fn make_executor<EM, S, Z>() -> impl Executor<EM, BytesInput, S, Z>
/// where
/// EM: UsesState,
/// EM::State: UsesInput<Input = BytesInput> + HasExecutions,
/// S: HasCorpus + HasExecutions,
/// S::Corpus: Corpus<Input = BytesInput>,
/// {
/// MyExecutor.into_executor(())
/// }
Expand Down Expand Up @@ -865,17 +867,18 @@ mod tests {
Executor,
},
fuzzer::NopFuzzer,
inputs::BytesInput,
inputs::{BytesInput, NopInput},
monitors::SimpleMonitor,
state::NopState,
};

#[test]
#[cfg_attr(miri, ignore)]
fn test_builder() {
let mut mgr = SimpleEventManager::new(SimpleMonitor::new(|status| {
log::info!("{status}");
}));
let mut mgr: SimpleEventManager<_, NopState<NopInput>> =
SimpleEventManager::new(SimpleMonitor::new(|status| {
log::info!("{status}");
}));

let mut executor = CommandExecutor::builder();
executor
Expand Down
47 changes: 18 additions & 29 deletions libafl/src/executors/inprocess_fork/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ use nix::{
#[cfg(all(unix, not(target_os = "linux")))]
use crate::executors::hooks::timer::{setitimer, Itimerval, Timeval, ITIMER_REAL};
use crate::{
events::{EventFirer, EventRestarter},
corpus::Corpus,
executors::{
hooks::{
inprocess_fork::{InChildProcessHooks, FORK_EXECUTOR_GLOBAL_DATA},
ExecutorHooksTuple,
},
ExitKind, HasObservers,
},
inputs::UsesInput,
observers::ObserversTuple,
state::{State, UsesState},
state::HasCorpus,
Error,
};

Expand Down Expand Up @@ -73,13 +72,6 @@ where
}
}

impl<HT, OT, S, SP, EM, Z> UsesState for GenericInProcessForkExecutorInner<HT, OT, S, SP, EM, Z>
where
S: State,
{
type State = S;
}

#[cfg(target_os = "linux")]
fn parse_itimerspec(timeout: Duration) -> libc::itimerspec {
let milli_sec = timeout.as_millis();
Expand Down Expand Up @@ -116,18 +108,17 @@ fn parse_itimerval(timeout: Duration) -> Itimerval {

impl<EM, HT, OT, S, SP, Z> GenericInProcessForkExecutorInner<HT, OT, S, SP, EM, Z>
where
OT: ObserversTuple<S::Input, S> + Debug,
S: State + UsesInput,
HT: ExecutorHooksTuple<<S::Corpus as Corpus>::Input, S>,
S: HasCorpus,
SP: ShMemProvider,
HT: ExecutorHooksTuple<S>,
EM: EventFirer<State = S> + EventRestarter<State = S>,
OT: ObserversTuple<<S::Corpus as Corpus>::Input, S>,
{
pub(super) unsafe fn pre_run_target_child(
&mut self,
fuzzer: &mut Z,
state: &mut <GenericInProcessForkExecutorInner<HT, OT, S, SP, EM, Z> as UsesState>::State,
state: &mut S,
mgr: &mut EM,
input: &<GenericInProcessForkExecutorInner<HT, OT, S, SP, EM, Z> as UsesInput>::Input,
input: &<S::Corpus as Corpus>::Input,
) -> Result<(), Error> {
self.shmem_provider.post_fork(true)?;

Expand Down Expand Up @@ -160,9 +151,9 @@ where
pub(super) unsafe fn post_run_target_child(
&mut self,
fuzzer: &mut Z,
state: &mut <GenericInProcessForkExecutorInner<HT, OT, S, SP, EM, Z> as UsesState>::State,
state: &mut S,
mgr: &mut EM,
input: &<GenericInProcessForkExecutorInner<HT, OT, S, SP, EM, Z> as UsesInput>::Input,
input: &<S::Corpus as Corpus>::Input,
) {
self.observers
.post_exec_child_all(state, input, &ExitKind::Ok)
Expand Down Expand Up @@ -209,18 +200,18 @@ where

impl<HT, OT, S, SP, EM, Z> GenericInProcessForkExecutorInner<HT, OT, S, SP, EM, Z>
where
HT: ExecutorHooksTuple<S>,
S: State,
OT: ObserversTuple<S::Input, S>,
HT: ExecutorHooksTuple<<S::Corpus as Corpus>::Input, S>,
OT: ObserversTuple<<S::Corpus as Corpus>::Input, S>,
S: HasCorpus,
{
#[inline]
/// This function marks the boundary between the fuzzer and the target.
pub fn enter_target(
&mut self,
_fuzzer: &mut Z,
state: &mut <Self as UsesState>::State,
state: &mut S,
_event_mgr: &mut EM,
input: &<Self as UsesInput>::Input,
input: &<S::Corpus as Corpus>::Input,
) {
unsafe {
let data = &raw mut FORK_EXECUTOR_GLOBAL_DATA;
Expand All @@ -245,9 +236,9 @@ where
pub fn leave_target(
&mut self,
_fuzzer: &mut Z,
_state: &mut <Self as UsesState>::State,
_state: &mut S,
_event_mgr: &mut EM,
_input: &<Self as UsesInput>::Input,
_input: &<S::Corpus as Corpus>::Input,
) {
// do nothing
}
Expand Down Expand Up @@ -303,10 +294,8 @@ where
}
}

impl<HT, OT, S, SP, EM, Z> HasObservers for GenericInProcessForkExecutorInner<HT, OT, S, SP, EM, Z>
where
OT: ObserversTuple<S::Input, S>,
S: State,
impl<HT, OT, S, SP, EM, Z> HasObservers
for GenericInProcessForkExecutorInner<HT, OT, S, SP, EM, Z>
{
type Observers = OT;

Expand Down
Loading

0 comments on commit 052b733

Please sign in to comment.