Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename HasCurrentStage to HasCurrentStageId for Consistency #2514

Merged
merged 1 commit into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libafl/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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> {
Expand Down
8 changes: 4 additions & 4 deletions libafl/src/fuzzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -769,7 +769,7 @@ where
+ HasTestcase
+ HasLastReportTime
+ HasCurrentCorpusId
+ HasCurrentStage,
+ HasCurrentStageId,
ST: StagesTuple<E, EM, Self::State, Self>,
{
fn fuzz_one(
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -977,7 +977,7 @@ pub mod test {
E: UsesState,
EM: ProgressReporter<State = Self::State> + EventProcessor<E, Self>,
ST: StagesTuple<E, EM, Self::State, Self>,
Self::State: HasMetadata + HasExecutions + HasLastReportTime + HasCurrentStage,
Self::State: HasMetadata + HasExecutions + HasLastReportTime + HasCurrentStageId,
{
fn fuzz_one(
&mut self,
Expand Down
14 changes: 7 additions & 7 deletions libafl/src/stages/logics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -192,29 +192,29 @@ 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
.perform_all(fuzzer, executor, state, manager)?;
}

state.exit_inner_stage()?;
state.clear_stage()?;
state.clear_stage_id()?;

Ok(())
}
Expand Down
30 changes: 15 additions & 15 deletions libafl/src/stages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ where
E: UsesState<State = S>,
EM: UsesState<State = S>,
Z: UsesState<State = S>,
S: UsesInput + HasCurrentStage,
S: UsesInput + HasCurrentStageId,
{
/// Performs all `Stages` in this tuple.
fn perform_all(
Expand All @@ -152,7 +152,7 @@ where
E: UsesState<State = S>,
EM: UsesState<State = S>,
Z: UsesState<State = S>,
S: UsesInput + HasCurrentStage,
S: UsesInput + HasCurrentStageId,
{
fn perform_all(
&mut self,
Expand All @@ -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.",
))
Expand All @@ -178,7 +178,7 @@ where
E: UsesState<State = Head::State>,
EM: UsesState<State = Head::State> + EventProcessor<E, Z>,
Z: UsesState<State = Head::State>,
Head::State: HasCurrentStage,
Head::State: HasCurrentStageId,
{
/// Performs all stages in the tuple,
/// Checks after every stage if state wants to stop
Expand All @@ -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
}
Expand All @@ -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()?;
}
}

Expand All @@ -237,7 +237,7 @@ where
E: UsesState<State = Head::State>,
EM: UsesState<State = Head::State>,
Z: UsesState<State = Head::State>,
Head::State: HasCurrentStage,
Head::State: HasCurrentStageId,
{
fn into_vec_reversed(
self,
Expand Down Expand Up @@ -286,7 +286,7 @@ where
E: UsesState<State = S>,
EM: UsesState<State = S> + EventProcessor<E, Z>,
Z: UsesState<State = S>,
S: UsesInput + HasCurrentStage + State,
S: UsesInput + HasCurrentStageId + State,
{
/// Performs all stages in the `Vec`
/// Checks after every stage if state wants to stop
Expand Down Expand Up @@ -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<Option<StageId>, Error>;
fn current_stage_id(&self) -> Result<Option<StageId>, Error>;

/// Notify of a reset from which we may recover
fn on_restart(&mut self) -> Result<(), Error> {
Expand All @@ -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>;
Expand Down
26 changes: 13 additions & 13 deletions libafl/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand All @@ -54,7 +54,7 @@ pub trait State:
+ MaybeHasClientPerfMonitor
+ MaybeHasScalabilityMonitor
+ HasCurrentCorpusId
+ HasCurrentStage
+ HasCurrentStageId
+ Stoppable
{
}
Expand Down Expand Up @@ -587,17 +587,17 @@ impl<I, C, R, SC> Stoppable for StdState<I, C, R, SC> {
}
}

impl<I, C, R, SC> HasCurrentStage for StdState<I, C, R, SC> {
fn set_current_stage_idx(&mut self, idx: StageId) -> Result<(), Error> {
self.stage_stack.set_current_stage_idx(idx)
impl<I, C, R, SC> HasCurrentStageId for StdState<I, C, R, SC> {
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<Option<StageId>, Error> {
self.stage_stack.current_stage_idx()
fn current_stage_id(&self) -> Result<Option<StageId>, Error> {
self.stage_stack.current_stage_id()
}

fn on_restart(&mut self) -> Result<(), Error> {
Expand Down Expand Up @@ -1300,16 +1300,16 @@ impl<I> HasCurrentCorpusId for NopState<I> {
}
}

impl<I> HasCurrentStage for NopState<I> {
fn set_current_stage_idx(&mut self, _idx: StageId) -> Result<(), Error> {
impl<I> HasCurrentStageId for NopState<I> {
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<Option<StageId>, Error> {
fn current_stage_id(&self) -> Result<Option<StageId>, Error> {
Ok(None)
}
}
Expand Down
10 changes: 5 additions & 5 deletions libafl/src/state/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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(
Expand All @@ -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<Option<StageId>, Error> {
fn current_stage_id(&self) -> Result<Option<StageId>, Error> {
Ok(self.stage_idx_stack.get(self.stage_depth).copied())
}

Expand Down
4 changes: 2 additions & 2 deletions libafl_libfuzzer/runtime/src/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -68,7 +68,7 @@ where
+ UsesInput
+ HasSolutions
+ HasLastReportTime
+ HasCurrentStage
+ HasCurrentStageId
+ Stoppable,
E: UsesState<State = S>,
EM: ProgressReporter<State = S> + EventProcessor<E, F>,
Expand Down
4 changes: 2 additions & 2 deletions libafl_libfuzzer/runtime/src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -29,7 +29,7 @@ where
+ HasExecutions
+ UsesInput
+ HasLastReportTime
+ HasCurrentStage
+ HasCurrentStageId
+ Stoppable,
E: HasObservers<State = S>,
EM: ProgressReporter<State = S> + EventProcessor<E, F>,
Expand Down
Loading