diff --git a/libafl/src/events/mod.rs b/libafl/src/events/mod.rs index db81bd09c5..656d9fbdaf 100644 --- a/libafl/src/events/mod.rs +++ b/libafl/src/events/mod.rs @@ -116,7 +116,7 @@ use crate::events::multi_machine::NodeId; #[cfg(feature = "introspection")] use crate::monitors::ClientPerfMonitor; use crate::{ - inputs::UsesInput, observers::TimeObserver, stages::HasCurrentStage, state::UsesState, + inputs::UsesInput, observers::TimeObserver, stages::HasCurrentStageId, state::UsesState, }; /// The log event severity @@ -545,7 +545,7 @@ where /// Restartable trait pub trait EventRestarter: UsesState { /// For restarting event managers, implement a way to forward state to their next peers. - /// You *must* ensure that [`HasCurrentStage::on_restart`] will be invoked in this method, by you + /// You *must* ensure that [`HasCurrentStageId::on_restart`] will be invoked in this method, by you /// or an internal [`EventRestarter`], before the state is saved for recovery. #[inline] fn on_restart(&mut self, state: &mut Self::State) -> Result<(), Error> { diff --git a/libafl/src/fuzzer/mod.rs b/libafl/src/fuzzer/mod.rs index 15d82f99d0..e9067a139d 100644 --- a/libafl/src/fuzzer/mod.rs +++ b/libafl/src/fuzzer/mod.rs @@ -15,7 +15,7 @@ use crate::{ mark_feature_time, observers::ObserversTuple, schedulers::Scheduler, - stages::{HasCurrentStage, StagesTuple}, + stages::{HasCurrentStageId, StagesTuple}, start_timer, state::{ HasCorpus, HasCurrentTestcase, HasExecutions, HasLastFoundTime, HasLastReportTime, @@ -769,7 +769,7 @@ where + HasTestcase + HasLastReportTime + HasCurrentCorpusId - + HasCurrentStage, + + HasCurrentStageId, ST: StagesTuple, { fn fuzz_one( @@ -940,7 +940,7 @@ pub mod test { use crate::{ corpus::CorpusId, events::{EventProcessor, ProgressReporter}, - stages::{HasCurrentStage, StagesTuple}, + stages::{HasCurrentStageId, StagesTuple}, state::{HasExecutions, HasLastReportTime, State, UsesState}, Fuzzer, HasMetadata, }; @@ -977,7 +977,7 @@ pub mod test { E: UsesState, EM: ProgressReporter + EventProcessor, ST: StagesTuple, - Self::State: HasMetadata + HasExecutions + HasLastReportTime + HasCurrentStage, + Self::State: HasMetadata + HasExecutions + HasLastReportTime + HasCurrentStageId, { fn fuzz_one( &mut self, diff --git a/libafl/src/stages/logics.rs b/libafl/src/stages/logics.rs index f7f74f6f4b..c05b818774 100644 --- a/libafl/src/stages/logics.rs +++ b/libafl/src/stages/logics.rs @@ -3,7 +3,7 @@ use core::marker::PhantomData; use crate::{ - stages::{HasCurrentStage, HasNestedStageStatus, Stage, StageId, StagesTuple}, + stages::{HasCurrentStageId, HasNestedStageStatus, Stage, StageId, StagesTuple}, state::UsesState, Error, }; @@ -61,7 +61,7 @@ where state: &mut Self::State, manager: &mut EM, ) -> Result<(), Error> { - while state.current_stage_idx()?.is_some() + while state.current_stage_id()?.is_some() || (self.closure)(fuzzer, executor, state, manager)? { self.stages.perform_all(fuzzer, executor, state, manager)?; @@ -126,7 +126,7 @@ where state: &mut Self::State, manager: &mut EM, ) -> Result<(), Error> { - if state.current_stage_idx()?.is_some() || (self.closure)(fuzzer, executor, state, manager)? + if state.current_stage_id()?.is_some() || (self.closure)(fuzzer, executor, state, manager)? { self.if_stages .perform_all(fuzzer, executor, state, manager)?; @@ -192,21 +192,21 @@ where state: &mut Self::State, manager: &mut EM, ) -> Result<(), Error> { - let current = state.current_stage_idx()?; + let current = state.current_stage_id()?; let fresh = current.is_none(); let closure_return = fresh && (self.closure)(fuzzer, executor, state, manager)?; if current == Some(StageId(0)) || closure_return { if fresh { - state.set_current_stage_idx(StageId(0))?; + state.set_current_stage_id(StageId(0))?; } state.enter_inner_stage()?; self.if_stages .perform_all(fuzzer, executor, state, manager)?; } else { if fresh { - state.set_current_stage_idx(StageId(1))?; + state.set_current_stage_id(StageId(1))?; } state.enter_inner_stage()?; self.else_stages @@ -214,7 +214,7 @@ where } state.exit_inner_stage()?; - state.clear_stage()?; + state.clear_stage_id()?; Ok(()) } diff --git a/libafl/src/stages/mod.rs b/libafl/src/stages/mod.rs index c318a64479..2d5fad48d0 100644 --- a/libafl/src/stages/mod.rs +++ b/libafl/src/stages/mod.rs @@ -135,7 +135,7 @@ where E: UsesState, EM: UsesState, Z: UsesState, - S: UsesInput + HasCurrentStage, + S: UsesInput + HasCurrentStageId, { /// Performs all `Stages` in this tuple. fn perform_all( @@ -152,7 +152,7 @@ where E: UsesState, EM: UsesState, Z: UsesState, - S: UsesInput + HasCurrentStage, + S: UsesInput + HasCurrentStageId, { fn perform_all( &mut self, @@ -161,7 +161,7 @@ where stage: &mut S, _: &mut EM, ) -> Result<(), Error> { - if stage.current_stage_idx()?.is_some() { + if stage.current_stage_id()?.is_some() { Err(Error::illegal_state( "Got to the end of the tuple without completing resume.", )) @@ -178,7 +178,7 @@ where E: UsesState, EM: UsesState + EventProcessor, Z: UsesState, - Head::State: HasCurrentStage, + Head::State: HasCurrentStageId, { /// Performs all stages in the tuple, /// Checks after every stage if state wants to stop @@ -190,7 +190,7 @@ where state: &mut Head::State, manager: &mut EM, ) -> Result<(), Error> { - match state.current_stage_idx()? { + match state.current_stage_id()? { Some(idx) if idx < StageId(Self::LEN) => { // do nothing; we are resuming } @@ -200,19 +200,19 @@ where stage.perform_restartable(fuzzer, executor, state, manager)?; - state.clear_stage()?; + state.clear_stage_id()?; } Some(idx) if idx > StageId(Self::LEN) => { unreachable!("We should clear the stage index before we get here..."); } // this is None, but the match can't deduce that _ => { - state.set_current_stage_idx(StageId(Self::LEN))?; + state.set_current_stage_id(StageId(Self::LEN))?; let stage = &mut self.0; stage.perform_restartable(fuzzer, executor, state, manager)?; - state.clear_stage()?; + state.clear_stage_id()?; } } @@ -237,7 +237,7 @@ where E: UsesState, EM: UsesState, Z: UsesState, - Head::State: HasCurrentStage, + Head::State: HasCurrentStageId, { fn into_vec_reversed( self, @@ -286,7 +286,7 @@ where E: UsesState, EM: UsesState + EventProcessor, Z: UsesState, - S: UsesInput + HasCurrentStage + State, + S: UsesInput + HasCurrentStageId + State, { /// Performs all stages in the `Vec` /// Checks after every stage if state wants to stop @@ -592,15 +592,15 @@ impl fmt::Display for StageId { } /// Trait for types which track the current stage -pub trait HasCurrentStage { +pub trait HasCurrentStageId { /// Set the current stage; we have started processing this stage - fn set_current_stage_idx(&mut self, idx: StageId) -> Result<(), Error>; + fn set_current_stage_id(&mut self, id: StageId) -> Result<(), Error>; /// Clear the current stage; we are done processing this stage - fn clear_stage(&mut self) -> Result<(), Error>; + fn clear_stage_id(&mut self) -> Result<(), Error>; /// Fetch the current stage -- typically used after a state recovery or transfer - fn current_stage_idx(&self) -> Result, Error>; + fn current_stage_id(&self) -> Result, Error>; /// Notify of a reset from which we may recover fn on_restart(&mut self) -> Result<(), Error> { @@ -610,7 +610,7 @@ pub trait HasCurrentStage { /// Trait for types which track nested stages. Stages which themselves contain stage tuples should /// ensure that they constrain the state with this trait accordingly. -pub trait HasNestedStageStatus: HasCurrentStage { +pub trait HasNestedStageStatus: HasCurrentStageId { /// Enter a stage scope, potentially resuming to an inner stage status. Returns Ok(true) if /// resumed. fn enter_inner_stage(&mut self) -> Result<(), Error>; diff --git a/libafl/src/state/mod.rs b/libafl/src/state/mod.rs index 85e20dbe83..bc364fdfb9 100644 --- a/libafl/src/state/mod.rs +++ b/libafl/src/state/mod.rs @@ -37,7 +37,7 @@ use crate::{ fuzzer::{Evaluator, ExecuteInputResult}, generators::Generator, inputs::{Input, UsesInput}, - stages::{HasCurrentStage, HasNestedStageStatus, StageId}, + stages::{HasCurrentStageId, HasNestedStageStatus, StageId}, Error, HasMetadata, HasNamedMetadata, }; @@ -54,7 +54,7 @@ pub trait State: + MaybeHasClientPerfMonitor + MaybeHasScalabilityMonitor + HasCurrentCorpusId - + HasCurrentStage + + HasCurrentStageId + Stoppable { } @@ -587,17 +587,17 @@ impl Stoppable for StdState { } } -impl HasCurrentStage for StdState { - fn set_current_stage_idx(&mut self, idx: StageId) -> Result<(), Error> { - self.stage_stack.set_current_stage_idx(idx) +impl HasCurrentStageId for StdState { + fn set_current_stage_id(&mut self, idx: StageId) -> Result<(), Error> { + self.stage_stack.set_current_stage_id(idx) } - fn clear_stage(&mut self) -> Result<(), Error> { - self.stage_stack.clear_stage() + fn clear_stage_id(&mut self) -> Result<(), Error> { + self.stage_stack.clear_stage_id() } - fn current_stage_idx(&self) -> Result, Error> { - self.stage_stack.current_stage_idx() + fn current_stage_id(&self) -> Result, Error> { + self.stage_stack.current_stage_id() } fn on_restart(&mut self) -> Result<(), Error> { @@ -1300,16 +1300,16 @@ impl HasCurrentCorpusId for NopState { } } -impl HasCurrentStage for NopState { - fn set_current_stage_idx(&mut self, _idx: StageId) -> Result<(), Error> { +impl HasCurrentStageId for NopState { + fn set_current_stage_id(&mut self, _idx: StageId) -> Result<(), Error> { Ok(()) } - fn clear_stage(&mut self) -> Result<(), Error> { + fn clear_stage_id(&mut self) -> Result<(), Error> { Ok(()) } - fn current_stage_idx(&self) -> Result, Error> { + fn current_stage_id(&self) -> Result, Error> { Ok(None) } } diff --git a/libafl/src/state/stack.rs b/libafl/src/state/stack.rs index 72c5828df5..c07278cfa8 100644 --- a/libafl/src/state/stack.rs +++ b/libafl/src/state/stack.rs @@ -3,7 +3,7 @@ use alloc::vec::Vec; use libafl_bolts::Error; use serde::{Deserialize, Serialize}; -use crate::stages::{HasCurrentStage, HasNestedStageStatus, StageId}; +use crate::stages::{HasCurrentStageId, HasNestedStageStatus, StageId}; /// A stack to keep track of which stage is executing #[derive(Serialize, Deserialize, Clone, Debug, Default)] @@ -14,8 +14,8 @@ pub struct StageStack { stage_depth: usize, } -impl HasCurrentStage for StageStack { - fn set_current_stage_idx(&mut self, idx: StageId) -> Result<(), Error> { +impl HasCurrentStageId for StageStack { + fn set_current_stage_id(&mut self, idx: StageId) -> Result<(), Error> { // ensure we are in the right frame if self.stage_depth != self.stage_idx_stack.len() { return Err(Error::illegal_state( @@ -26,12 +26,12 @@ impl HasCurrentStage for StageStack { Ok(()) } - fn clear_stage(&mut self) -> Result<(), Error> { + fn clear_stage_id(&mut self) -> Result<(), Error> { self.stage_idx_stack.truncate(self.stage_depth); Ok(()) } - fn current_stage_idx(&self) -> Result, Error> { + fn current_stage_id(&self) -> Result, Error> { Ok(self.stage_idx_stack.get(self.stage_depth).copied()) } diff --git a/libafl_libfuzzer/runtime/src/fuzz.rs b/libafl_libfuzzer/runtime/src/fuzz.rs index 95cccbb1cc..94f3954559 100644 --- a/libafl_libfuzzer/runtime/src/fuzz.rs +++ b/libafl_libfuzzer/runtime/src/fuzz.rs @@ -19,7 +19,7 @@ use libafl::{ executors::ExitKind, inputs::UsesInput, monitors::{tui::TuiMonitor, Monitor, MultiMonitor}, - stages::{HasCurrentStage, StagesTuple}, + stages::{HasCurrentStageId, StagesTuple}, state::{HasExecutions, HasLastReportTime, HasSolutions, Stoppable, UsesState}, Error, Fuzzer, HasMetadata, }; @@ -68,7 +68,7 @@ where + UsesInput + HasSolutions + HasLastReportTime - + HasCurrentStage + + HasCurrentStageId + Stoppable, E: UsesState, EM: ProgressReporter + EventProcessor, diff --git a/libafl_libfuzzer/runtime/src/report.rs b/libafl_libfuzzer/runtime/src/report.rs index 557e8d67f6..d7992eb020 100644 --- a/libafl_libfuzzer/runtime/src/report.rs +++ b/libafl_libfuzzer/runtime/src/report.rs @@ -6,7 +6,7 @@ use libafl::{ feedbacks::MapFeedbackMetadata, inputs::UsesInput, monitors::SimpleMonitor, - stages::{HasCurrentStage, StagesTuple}, + stages::{HasCurrentStageId, StagesTuple}, state::{HasExecutions, HasLastReportTime, Stoppable}, Error, Fuzzer, HasMetadata, HasNamedMetadata, }; @@ -29,7 +29,7 @@ where + HasExecutions + UsesInput + HasLastReportTime - + HasCurrentStage + + HasCurrentStageId + Stoppable, E: HasObservers, EM: ProgressReporter + EventProcessor,