From a32fab65f10ce18b600c75a02779457727367ddb Mon Sep 17 00:00:00 2001 From: aarnav Date: Tue, 2 Jul 2024 15:23:24 +0200 Subject: [PATCH] rename initate_stop to request_stop, should_stop to stop_requested and reset_stop to discard_stop_request --- libafl/src/events/centralized.rs | 2 +- libafl/src/events/llmp/mgr.rs | 2 +- libafl/src/events/simple.rs | 2 +- libafl/src/events/tcp.rs | 2 +- libafl/src/fuzzer/mod.rs | 8 +++--- libafl/src/stages/mod.rs | 8 +++--- libafl/src/state/mod.rs | 45 ++++++++++++++++---------------- 7 files changed, 35 insertions(+), 34 deletions(-) diff --git a/libafl/src/events/centralized.rs b/libafl/src/events/centralized.rs index 3857ad76ab..5c7a30beeb 100644 --- a/libafl/src/events/centralized.rs +++ b/libafl/src/events/centralized.rs @@ -670,7 +670,7 @@ where } } Event::Stop => { - state.initiate_stop(); + state.request_stop(); } _ => { return Err(Error::unknown(format!( diff --git a/libafl/src/events/llmp/mgr.rs b/libafl/src/events/llmp/mgr.rs index a6f81a729a..33816bbf80 100644 --- a/libafl/src/events/llmp/mgr.rs +++ b/libafl/src/events/llmp/mgr.rs @@ -470,7 +470,7 @@ where } } Event::Stop => { - state.initiate_stop(); + state.request_stop(); } _ => { return Err(Error::unknown(format!( diff --git a/libafl/src/events/simple.rs b/libafl/src/events/simple.rs index 646e9b8335..ce17d038fb 100644 --- a/libafl/src/events/simple.rs +++ b/libafl/src/events/simple.rs @@ -300,7 +300,7 @@ where Ok(()) } Event::Stop => { - state.initiate_stop(); + state.request_stop(); Ok(()) } _ => Err(Error::unknown(format!( diff --git a/libafl/src/events/tcp.rs b/libafl/src/events/tcp.rs index e9f1754cc3..2233fecfad 100644 --- a/libafl/src/events/tcp.rs +++ b/libafl/src/events/tcp.rs @@ -658,7 +658,7 @@ where } } Event::Stop => { - state.initiate_stop(); + state.request_stop(); } _ => { return Err(Error::unknown(format!( diff --git a/libafl/src/fuzzer/mod.rs b/libafl/src/fuzzer/mod.rs index 7ba4d5cb8b..c772bec360 100644 --- a/libafl/src/fuzzer/mod.rs +++ b/libafl/src/fuzzer/mod.rs @@ -216,8 +216,8 @@ where loop { // log::info!("Starting another fuzz_loop"); manager.maybe_report_progress(state, monitor_timeout)?; - if state.should_stop() { - state.reset_stop(); + if state.stop_requested() { + state.discard_stop_request(); manager.on_shutdown()?; break; } @@ -254,8 +254,8 @@ where for _ in 0..iters { manager.maybe_report_progress(state, monitor_timeout)?; - if state.should_stop() { - state.reset_stop(); + if state.stop_requested() { + state.discard_stop_request(); break; } ret = Some(self.fuzz_one(stages, executor, state, manager)?); diff --git a/libafl/src/stages/mod.rs b/libafl/src/stages/mod.rs index 38120f395d..d4e40c97d1 100644 --- a/libafl/src/stages/mod.rs +++ b/libafl/src/stages/mod.rs @@ -214,8 +214,8 @@ where } } - if state.should_stop() { - state.reset_stop(); + if state.stop_requested() { + state.discard_stop_request(); manager.on_shutdown()?; return Err(Error::shutting_down()); } @@ -297,8 +297,8 @@ where manager: &mut EM, ) -> Result<(), Error> { self.iter_mut().try_for_each(|x| { - if state.should_stop() { - state.reset_stop(); + if state.stop_requested() { + state.discard_stop_request(); manager.on_shutdown()?; return Err(Error::shutting_down()); } diff --git a/libafl/src/state/mod.rs b/libafl/src/state/mod.rs index ccc04a9243..e31efb3efc 100644 --- a/libafl/src/state/mod.rs +++ b/libafl/src/state/mod.rs @@ -262,8 +262,9 @@ pub struct StdState { last_report_time: Option, /// The current index of the corpus; used to record for resumable fuzzing. corpus_id: Option, - /// Tell the fuzzer to stop at the start of the next fuzzing iteration. - should_stop: bool, + /// Request the fuzzer to stop at the start of the next stage + /// or at the beginning of the next fuzzing iteration + stop_requested: bool, stage_stack: StageStack, phantom: PhantomData, } @@ -537,27 +538,27 @@ where /// A trait for types that want to expose a stop API pub trait Stoppable { - /// Check if should stop - fn should_stop(&self) -> bool; + /// Check if stop is requested + fn stop_requested(&self) -> bool; /// Request to stop - fn initiate_stop(&mut self); + fn request_stop(&mut self); - /// Reset stop value - fn reset_stop(&mut self); + /// Discard the stop request + fn discard_stop_request(&mut self); } impl Stoppable for StdState { - fn initiate_stop(&mut self) { - self.should_stop = true; + fn request_stop(&mut self) { + self.stop_requested = true; } - fn reset_stop(&mut self) { - self.should_stop = false; + fn discard_stop_request(&mut self) { + self.stop_requested = false; } - fn should_stop(&self) -> bool { - self.should_stop + fn stop_requested(&self) -> bool { + self.stop_requested } } @@ -1116,7 +1117,7 @@ where corpus, solutions, max_size: DEFAULT_MAX_SIZE, - should_stop: false, + stop_requested: false, #[cfg(feature = "introspection")] introspection_monitor: ClientPerfMonitor::new(), #[cfg(feature = "scalability_introspection")] @@ -1165,7 +1166,7 @@ impl HasScalabilityMonitor for StdState { pub struct NopState { metadata: SerdeAnyMap, execution: u64, - should_stop: bool, + stop_requested: bool, rand: StdRand, phantom: PhantomData, } @@ -1178,7 +1179,7 @@ impl NopState { metadata: SerdeAnyMap::new(), execution: 0, rand: StdRand::default(), - should_stop: false, + stop_requested: false, phantom: PhantomData, } } @@ -1212,16 +1213,16 @@ impl HasExecutions for NopState { } impl Stoppable for NopState { - fn initiate_stop(&mut self) { - self.should_stop = true; + fn request_stop(&mut self) { + self.stop_requested = true; } - fn reset_stop(&mut self) { - self.should_stop = false; + fn discard_stop_request(&mut self) { + self.stop_requested = false; } - fn should_stop(&self) -> bool { - self.should_stop + fn stop_requested(&self) -> bool { + self.stop_requested } }