@@ -57,12 +57,12 @@ use typed_builder::TypedBuilder;
5757
5858#[ cfg( all( target_family = "unix" , feature = "fork" ) ) ]
5959use super :: forkserver:: ConfigTarget ;
60- use super :: { HasTimeout , StdChildArgs , StdChildArgsInner } ;
60+ use super :: { StdChildArgs , StdChildArgsInner } ;
6161#[ cfg( target_os = "linux" ) ]
6262use crate :: executors:: hooks:: ExecutorHooksTuple ;
6363use crate :: {
6464 Error ,
65- executors:: { Executor , ExitKind , HasObservers } ,
65+ executors:: { Executor , ExitKind , HasObservers , HasTimeout , SetTimeout } ,
6666 inputs:: { HasTargetBytes , ToTargetBytes } ,
6767 observers:: { ObserversTuple , StdErrObserver , StdOutObserver } ,
6868 state:: HasExecutions ,
@@ -204,19 +204,26 @@ impl CommandConfigurator<Child> for StdCommandConfigurator {
204204 }
205205 }
206206 }
207+ }
207208
208- fn exec_timeout ( & self ) -> Duration {
209+ impl HasTimeout for StdCommandConfigurator {
210+ fn timeout ( & self ) -> Duration {
209211 self . timeout
210212 }
211- fn exec_timeout_mut ( & mut self ) -> & mut Duration {
212- & mut self . timeout
213+ }
214+
215+ impl SetTimeout for StdCommandConfigurator {
216+ fn set_timeout ( & mut self , timeout : Duration ) {
217+ self . timeout = timeout;
213218 }
214219}
215220
216221/// Linux specific [`CommandConfigurator`] that leverages `ptrace`
217222///
218223/// This configurator was primarily developed to be used in conjunction with
219224/// [`crate::executors::hooks::intel_pt::IntelPTHook`]
225+ ///
226+ /// Use `PTraceCommandConfigurator::builder().timeout` to set an initial timeout
220227#[ cfg( all( feature = "intel_pt" , target_os = "linux" ) ) ]
221228#[ derive( Debug , Clone , PartialEq , Eq , TypedBuilder ) ]
222229pub struct PTraceCommandConfigurator {
@@ -300,15 +307,13 @@ impl CommandConfigurator<Pid> for PTraceCommandConfigurator {
300307 Err ( e) => Err ( Error :: unknown ( format ! ( "Fork failed: {e}" ) ) ) ,
301308 }
302309 }
310+ }
303311
304- fn exec_timeout ( & self ) -> Duration {
312+ #[ cfg( all( feature = "intel_pt" , target_os = "linux" ) ) ]
313+ impl HasTimeout for PTraceCommandConfigurator {
314+ fn timeout ( & self ) -> Duration {
305315 Duration :: from_secs ( u64:: from ( self . timeout ) )
306316 }
307-
308- /// Use [`PTraceCommandConfigurator::builder()`](PTraceCommandConfigurator) instead
309- fn exec_timeout_mut ( & mut self ) -> & mut Duration {
310- unimplemented ! ( "Use [`PTraceCommandConfigurator::builder().timeout`] instead" )
311- }
312317}
313318
314319/// A `CommandExecutor` is a wrapper around [`Command`] to execute a target as a child process.
@@ -372,7 +377,7 @@ impl<C, HT, I, OT, S, T> CommandExecutor<C, HT, I, OT, S, T> {
372377impl < HT , I , OT , S , T > CommandExecutor < Child , HT , I , OT , S , T >
373378where
374379 S : HasExecutions ,
375- T : CommandConfigurator < Child > + Debug ,
380+ T : CommandConfigurator < Child > + HasTimeout + Debug ,
376381 OT : ObserversTuple < I , S > ,
377382{
378383 fn execute_input_with_command < TB : ToTargetBytes < I > > (
@@ -390,7 +395,7 @@ where
390395 . spawn_child ( target_bytes_converter. to_target_bytes ( input) ) ?;
391396
392397 let exit_kind = child
393- . wait_timeout ( self . configurator . exec_timeout ( ) )
398+ . wait_timeout ( self . configurator . timeout ( ) )
394399 . expect ( "waiting on child failed" )
395400 . map ( |status| self . configurator . exit_kind_from_status ( & status) )
396401 . unwrap_or_else ( || {
@@ -431,7 +436,7 @@ where
431436impl < EM , HT , I , OT , S , T , Z > Executor < EM , I , S , Z > for CommandExecutor < Child , HT , I , OT , S , T >
432437where
433438 S : HasExecutions ,
434- T : CommandConfigurator < Child > + Debug ,
439+ T : CommandConfigurator < Child > + HasTimeout + Debug ,
435440 OT : MatchName + ObserversTuple < I , S > ,
436441 Z : ToTargetBytes < I > ,
437442{
@@ -449,16 +454,21 @@ where
449454// this only works on unix because of the reliance on checking the process signal for detecting OOM
450455impl < C , HT , I , OT , S , T > HasTimeout for CommandExecutor < C , HT , I , OT , S , T >
451456where
452- T : CommandConfigurator < C > ,
457+ T : HasTimeout ,
453458{
454459 #[ inline]
455460 fn timeout ( & self ) -> Duration {
456- self . configurator . exec_timeout ( )
461+ self . configurator . timeout ( )
457462 }
463+ }
458464
465+ impl < C , HT , I , OT , S , T > SetTimeout for CommandExecutor < C , HT , I , OT , S , T >
466+ where
467+ T : SetTimeout ,
468+ {
459469 #[ inline]
460470 fn set_timeout ( & mut self , timeout : Duration ) {
461- * self . configurator . exec_timeout_mut ( ) = timeout;
471+ self . configurator . set_timeout ( timeout) ;
462472 }
463473}
464474
@@ -742,7 +752,7 @@ impl CommandExecutorBuilder {
742752/// use libafl::{
743753/// Error, HasTargetBytesConverter,
744754/// corpus::Corpus,
745- /// executors::{Executor, command::CommandConfigurator},
755+ /// executors::{Executor, HasTimeout, command::CommandConfigurator},
746756/// inputs::{BytesInput, HasTargetBytes, Input, ToTargetBytes},
747757/// state::HasExecutions,
748758/// };
@@ -763,13 +773,12 @@ impl CommandExecutorBuilder {
763773/// stdin.write_all(&target_bytes)?;
764774/// Ok(child)
765775/// }
776+ /// }
766777///
767- /// fn exec_timeout(&self) -> Duration {
778+ /// impl HasTimeout for MyExecutor {
779+ /// fn timeout(&self) -> Duration {
768780/// Duration::from_secs(5)
769781/// }
770- /// fn exec_timeout_mut(&mut self) -> &mut Duration {
771- /// todo!()
772- /// }
773782/// }
774783///
775784/// fn make_executor<EM, S, Z>() -> impl Executor<EM, BytesInput, S, Z>
@@ -793,11 +802,6 @@ pub trait CommandConfigurator<C>: Sized {
793802 /// Spawns a new process with the given configuration.
794803 fn spawn_child ( & mut self , target_bytes : OwnedSlice < ' _ , u8 > ) -> Result < C , Error > ;
795804
796- /// Provides timeout duration for execution of the child process.
797- fn exec_timeout ( & self ) -> Duration ;
798- /// Set the timeout duration for execution of the child process.
799- fn exec_timeout_mut ( & mut self ) -> & mut Duration ;
800-
801805 /// Maps the exit status of the child process to an `ExitKind`.
802806 #[ cfg( unix) ]
803807 #[ inline]
0 commit comments