diff --git a/libafl/src/corpus/mod.rs b/libafl/src/corpus/mod.rs index 021b592e27..21bb9f3259 100644 --- a/libafl/src/corpus/mod.rs +++ b/libafl/src/corpus/mod.rs @@ -175,7 +175,7 @@ pub trait Corpus: UsesInput + Serialize + for<'de> Deserialize<'de> { } /// Trait for types which track the current corpus index -pub trait HasCurrentCorpusIdx { +pub trait HasCurrentCorpusId { /// Set the current corpus index; we have started processing this corpus entry fn set_corpus_idx(&mut self, idx: CorpusId) -> Result<(), Error>; @@ -183,7 +183,7 @@ pub trait HasCurrentCorpusIdx { fn clear_corpus_idx(&mut self) -> Result<(), Error>; /// Fetch the current corpus index -- typically used after a state recovery or transfer - fn current_corpus_idx(&self) -> Result, Error>; + fn current_corpus_id(&self) -> Result, Error>; } /// [`Iterator`] over the ids of a [`Corpus`] diff --git a/libafl/src/fuzzer/mod.rs b/libafl/src/fuzzer/mod.rs index f55016573e..09fc4ff144 100644 --- a/libafl/src/fuzzer/mod.rs +++ b/libafl/src/fuzzer/mod.rs @@ -7,7 +7,7 @@ use libafl_bolts::current_time; use serde::{de::DeserializeOwned, Serialize}; use crate::{ - corpus::{Corpus, CorpusId, HasCurrentCorpusIdx, HasTestcase, Testcase}, + corpus::{Corpus, CorpusId, HasCurrentCorpusId, HasTestcase, Testcase}, events::{Event, EventConfig, EventFirer, EventProcessor, ProgressReporter}, executors::{Executor, ExitKind, HasObservers}, feedbacks::Feedback, @@ -369,7 +369,7 @@ where + HasCorpus + HasImported + HasCurrentTestcase<::Input> - + HasCurrentCorpusIdx, + + HasCurrentCorpusId, { fn execute_no_process( &mut self, @@ -697,7 +697,7 @@ where + HasTestcase + HasImported + HasLastReportTime - + HasCurrentCorpusIdx + + HasCurrentCorpusId + HasCurrentStage, ST: StagesTuple, { @@ -713,7 +713,7 @@ where state.introspection_monitor_mut().start_timer(); // Get the next index from the scheduler - let idx = if let Some(idx) = state.current_corpus_idx()? { + let idx = if let Some(idx) = state.current_corpus_id()? { idx // we are resuming } else { let idx = self.scheduler.next(state)?; diff --git a/libafl/src/mutators/token_mutations.rs b/libafl/src/mutators/token_mutations.rs index 03d221a64a..7b219e8e73 100644 --- a/libafl/src/mutators/token_mutations.rs +++ b/libafl/src/mutators/token_mutations.rs @@ -23,7 +23,7 @@ use serde::{Deserialize, Serialize}; #[cfg(feature = "std")] use crate::mutators::str_decode; use crate::{ - corpus::{CorpusId, HasCurrentCorpusIdx}, + corpus::{CorpusId, HasCurrentCorpusId}, inputs::{HasBytesVec, UsesInput}, mutators::{ buffer_self_copy, mutations::buffer_copy, MultiMutator, MutationResult, Mutator, Named, @@ -1087,7 +1087,7 @@ impl AFLppRedQueen { impl MultiMutator for AFLppRedQueen where - S: UsesInput + HasMetadata + HasRand + HasMaxSize + HasCorpus + HasCurrentCorpusIdx, + S: UsesInput + HasMetadata + HasRand + HasMaxSize + HasCorpus + HasCurrentCorpusId, I: HasBytesVec + From>, { #[allow(clippy::needless_range_loop)] @@ -1135,10 +1135,10 @@ where // println!("orig: {:#?} new: {:#?}", orig_cmpvals, new_cmpvals); // Compute when mutating it for the 1st time. - let current_corpus_idx = state.current_corpus_idx()?.ok_or_else(|| Error::key_not_found("No corpus-idx is currently being fuzzed, but called AFLppRedQueen::multi_mutated()."))?; - if self.last_corpus_idx.is_none() || self.last_corpus_idx.unwrap() != current_corpus_idx { + let current_corpus_id = state.current_corpus_id()?.ok_or_else(|| Error::key_not_found("No corpus-idx is currently being fuzzed, but called AFLppRedQueen::multi_mutated()."))?; + if self.last_corpus_idx.is_none() || self.last_corpus_idx.unwrap() != current_corpus_id { self.text_type = check_if_text(orig_bytes, orig_bytes.len()); - self.last_corpus_idx = Some(current_corpus_idx); + self.last_corpus_idx = Some(current_corpus_id); } // println!("approximate size: {cmp_len} x {input_len}"); for cmp_idx in 0..cmp_len { diff --git a/libafl/src/stages/generalization.rs b/libafl/src/stages/generalization.rs index 40d65707ee..0495ca3040 100644 --- a/libafl/src/stages/generalization.rs +++ b/libafl/src/stages/generalization.rs @@ -9,7 +9,7 @@ use libafl_bolts::{ }; use crate::{ - corpus::{Corpus, HasCurrentCorpusIdx}, + corpus::{Corpus, HasCurrentCorpusId}, executors::{Executor, HasObservers}, feedbacks::map::MapNoveltiesMetadata, inputs::{BytesInput, GeneralizedInputMetadata, GeneralizedItem, HasBytesVec, UsesInput}, @@ -83,7 +83,7 @@ where state: &mut E::State, manager: &mut EM, ) -> Result<(), Error> { - let Some(corpus_idx) = state.current_corpus_idx()? else { + let Some(corpus_idx) = state.current_corpus_id()? else { return Err(Error::illegal_state( "state is not currently processing a corpus index", )); diff --git a/libafl/src/stages/mod.rs b/libafl/src/stages/mod.rs index d6e711a3c0..1b6813a9d8 100644 --- a/libafl/src/stages/mod.rs +++ b/libafl/src/stages/mod.rs @@ -39,7 +39,7 @@ pub use tuneable::*; use tuple_list::NonEmptyTuple; use crate::{ - corpus::{CorpusId, HasCurrentCorpusIdx}, + corpus::{CorpusId, HasCurrentCorpusId}, events::{EventFirer, EventRestarter, HasEventManagerId, ProgressReporter}, executors::{Executor, HasObservers}, inputs::UsesInput, @@ -401,7 +401,7 @@ impl Stage for PushStageAdapter + HasObservers, EM: EventFirer + EventRestarter @@ -423,13 +423,13 @@ where ) -> Result<(), Error> { let push_stage = &mut self.push_stage; - let Some(corpus_idx) = state.current_corpus_idx()? else { + let Some(corpus_idx) = state.current_corpus_id()? else { return Err(Error::illegal_state( "state is not currently processing a corpus index", )); }; - push_stage.set_current_corpus_idx(corpus_idx); + push_stage.set_current_corpus_id(corpus_idx); push_stage.init(fuzzer, state, event_mgr, &mut *executor.observers_mut())?; @@ -490,12 +490,12 @@ impl RetryRestartHelper { max_retries: usize, ) -> Result where - S: HasNamedMetadata + HasCurrentCorpusIdx, + S: HasNamedMetadata + HasCurrentCorpusId, ST: Named, { - let corpus_idx = state.current_corpus_idx()?.ok_or_else(|| { + let corpus_idx = state.current_corpus_id()?.ok_or_else(|| { Error::illegal_state( - "No current_corpus_idx set in State, but called RetryRestartHelper::should_skip", + "No current_corpus_id set in State, but called RetryRestartHelper::should_skip", ) })?; @@ -655,7 +655,7 @@ pub mod test { use serde::{Deserialize, Serialize}; use crate::{ - corpus::{Corpus, HasCurrentCorpusIdx, Testcase}, + corpus::{Corpus, HasCurrentCorpusId, Testcase}, inputs::NopInput, stages::{RetryRestartHelper, Stage}, state::{test::test_std_state, HasCorpus, State, UsesState}, diff --git a/libafl/src/stages/push/mod.rs b/libafl/src/stages/push/mod.rs index 239363e011..3db9a18c8d 100644 --- a/libafl/src/stages/push/mod.rs +++ b/libafl/src/stages/push/mod.rs @@ -98,7 +98,7 @@ where pub errored: bool, /// The corpus index we're currently working on - pub current_corpus_idx: Option, + pub current_corpus_id: Option, /// The input we just ran pub current_input: Option<::Input>, // Todo: Get rid of copy @@ -132,7 +132,7 @@ where exit_kind: exit_kind_ref, errored: false, current_input: None, - current_corpus_idx: None, + current_corpus_id: None, } } @@ -167,7 +167,7 @@ where fn end_of_iter(&mut self, shared_state: PushStageSharedState, errored: bool) { self.set_shared_state(shared_state); self.errored = errored; - self.current_corpus_idx = None; + self.current_corpus_id = None; if errored { self.initialized = false; } @@ -193,8 +193,8 @@ where fn push_stage_helper_mut(&mut self) -> &mut PushStageHelper; /// Set the current corpus index this stage works on - fn set_current_corpus_idx(&mut self, corpus_idx: CorpusId) { - self.push_stage_helper_mut().current_corpus_idx = Some(corpus_idx); + fn set_current_corpus_id(&mut self, corpus_idx: CorpusId) { + self.push_stage_helper_mut().current_corpus_id = Some(corpus_idx); } /// Called by `next_std` when this stage is being initialized. diff --git a/libafl/src/stages/push/mutational.rs b/libafl/src/stages/push/mutational.rs index 976f854b0e..4bfcb4511e 100644 --- a/libafl/src/stages/push/mutational.rs +++ b/libafl/src/stages/push/mutational.rs @@ -49,7 +49,7 @@ where + EvaluatorObservers + HasScheduler, { - current_corpus_idx: Option, + current_corpus_id: Option, testcases_to_do: usize, testcases_done: usize, @@ -76,8 +76,8 @@ where } /// Sets the current corpus index - pub fn set_current_corpus_idx(&mut self, current_corpus_idx: CorpusId) { - self.current_corpus_idx = Some(current_corpus_idx); + pub fn set_current_corpus_id(&mut self, current_corpus_id: CorpusId) { + self.current_corpus_id = Some(current_corpus_id); } } @@ -112,13 +112,13 @@ where _observers: &mut OT, ) -> Result<(), Error> { // Find a testcase to work on, unless someone already set it - self.current_corpus_idx = Some(if let Some(corpus_idx) = self.current_corpus_idx { + self.current_corpus_id = Some(if let Some(corpus_idx) = self.current_corpus_id { corpus_idx } else { fuzzer.scheduler_mut().next(state)? }); - self.testcases_to_do = self.iterations(state, self.current_corpus_idx.unwrap())?; + self.testcases_to_do = self.iterations(state, self.current_corpus_id.unwrap())?; self.testcases_done = 0; Ok(()) } @@ -139,7 +139,7 @@ where let input = state .corpus_mut() - .cloned_input_for_id(self.current_corpus_idx.unwrap()); + .cloned_input_for_id(self.current_corpus_id.unwrap()); let mut input = match input { Err(e) => return Some(Err(e)), Ok(input) => input, @@ -172,7 +172,7 @@ where fuzzer.execute_and_process(state, event_mgr, last_input, observers, &exit_kind, true)?; start_timer!(state); - self.mutator.post_exec(state, self.current_corpus_idx)?; + self.mutator.post_exec(state, self.current_corpus_id)?; mark_feature_time!(state, PerfFeature::MutatePostExec); self.testcases_done += 1; @@ -187,7 +187,7 @@ where _event_mgr: &mut EM, _observers: &mut OT, ) -> Result<(), Error> { - self.current_corpus_idx = None; + self.current_corpus_id = None; Ok(()) } } @@ -233,7 +233,7 @@ where Self { mutator, psh: PushStageHelper::new(shared_state, exit_kind), - current_corpus_idx: None, // todo + current_corpus_id: None, // todo testcases_to_do: 0, testcases_done: 0, } diff --git a/libafl/src/stages/stats.rs b/libafl/src/stages/stats.rs index 59ba9655cb..fdb6282090 100644 --- a/libafl/src/stages/stats.rs +++ b/libafl/src/stages/stats.rs @@ -9,7 +9,7 @@ use libafl_bolts::current_time; use serde_json::json; use crate::{ - corpus::{Corpus, HasCurrentCorpusIdx}, + corpus::{Corpus, HasCurrentCorpusId}, events::EventFirer, schedulers::minimizer::IsFavoredMetadata, stages::Stage, @@ -69,7 +69,7 @@ where state: &mut E::State, _manager: &mut EM, ) -> Result<(), Error> { - let Some(corpus_idx) = state.current_corpus_idx()? else { + let Some(corpus_idx) = state.current_corpus_id()? else { return Err(Error::illegal_state( "state is not currently processing a corpus index", )); diff --git a/libafl/src/stages/tmin.rs b/libafl/src/stages/tmin.rs index 01d2f28715..cc83120ab4 100644 --- a/libafl/src/stages/tmin.rs +++ b/libafl/src/stages/tmin.rs @@ -10,7 +10,7 @@ use libafl_bolts::{ }; use crate::{ - corpus::{Corpus, HasCurrentCorpusIdx, Testcase}, + corpus::{Corpus, HasCurrentCorpusId, Testcase}, events::EventFirer, executors::{Executor, ExitKind, HasObservers}, feedbacks::{Feedback, FeedbackFactory, HasObserverHandle}, @@ -72,7 +72,7 @@ where state: &mut CS::State, manager: &mut EM, ) -> Result<(), Error> { - let Some(base_corpus_idx) = state.current_corpus_idx()? else { + let Some(base_corpus_idx) = state.current_corpus_id()? else { return Err(Error::illegal_state( "state is not currently processing a corpus index", )); diff --git a/libafl/src/state/mod.rs b/libafl/src/state/mod.rs index 60bf021416..3c6268f2e1 100644 --- a/libafl/src/state/mod.rs +++ b/libafl/src/state/mod.rs @@ -27,7 +27,7 @@ use crate::monitors::ClientPerfMonitor; #[cfg(feature = "scalability_introspection")] use crate::monitors::ScalabilityMonitor; use crate::{ - corpus::{Corpus, CorpusId, HasCurrentCorpusIdx, HasTestcase, Testcase}, + corpus::{Corpus, CorpusId, HasCurrentCorpusId, HasTestcase, Testcase}, events::{Event, EventFirer, LogSeverity}, feedbacks::Feedback, fuzzer::{Evaluator, ExecuteInputResult}, @@ -49,7 +49,7 @@ pub trait State: + DeserializeOwned + MaybeHasClientPerfMonitor + MaybeHasScalabilityMonitor - + HasCurrentCorpusIdx + + HasCurrentCorpusId + HasCurrentStage { } @@ -457,7 +457,7 @@ impl HasStartTime for StdState { } } -impl HasCurrentCorpusIdx for StdState { +impl HasCurrentCorpusId for StdState { fn set_corpus_idx(&mut self, idx: CorpusId) -> Result<(), Error> { self.corpus_idx = Some(idx); Ok(()) @@ -468,7 +468,7 @@ impl HasCurrentCorpusIdx for StdState { Ok(()) } - fn current_corpus_idx(&self) -> Result, Error> { + fn current_corpus_id(&self) -> Result, Error> { Ok(self.corpus_idx) } } @@ -503,10 +503,10 @@ where impl HasCurrentTestcase for T where I: Input, - T: HasCorpus + HasCurrentCorpusIdx + UsesInput, + T: HasCorpus + HasCurrentCorpusId + UsesInput, { fn current_testcase(&self) -> Result>, Error> { - let Some(corpus_id) = self.current_corpus_idx()? else { + let Some(corpus_id) = self.current_corpus_id()? else { return Err(Error::key_not_found( "We are not currently processing a testcase", )); @@ -516,7 +516,7 @@ where } fn current_testcase_mut(&self) -> Result>, Error> { - let Some(corpus_id) = self.current_corpus_idx()? else { + let Some(corpus_id) = self.current_corpus_id()? else { return Err(Error::illegal_state( "We are not currently processing a testcase", )); @@ -1214,7 +1214,7 @@ impl HasRand for NopState { impl State for NopState where I: Input {} -impl HasCurrentCorpusIdx for NopState { +impl HasCurrentCorpusId for NopState { fn set_corpus_idx(&mut self, _idx: CorpusId) -> Result<(), Error> { Ok(()) } @@ -1223,7 +1223,7 @@ impl HasCurrentCorpusIdx for NopState { Ok(()) } - fn current_corpus_idx(&self) -> Result, Error> { + fn current_corpus_id(&self) -> Result, Error> { Ok(None) } }