Trait libafl::executors::command::CommandConfigurator

source ·
pub trait CommandConfigurator<I>: Sized {
    // Required methods
    fn spawn_child(&mut self, input: &I) -> Result<Child, Error>;
    fn exec_timeout(&self) -> Duration;

    // Provided methods
    fn stdout_observer(&self) -> Option<Handle<StdOutObserver>> { ... }
    fn stderr_observer(&self) -> Option<Handle<StdErrObserver>> { ... }
    fn into_executor<OT, S>(self, observers: OT) -> CommandExecutor<OT, S, Self>
       where OT: MatchName { ... }
}
Expand description

A CommandConfigurator takes care of creating and spawning a std::process::Command for the CommandExecutor.

§Example

use std::{io::Write, process::{Stdio, Command, Child}, time::Duration};
use libafl::{Error, inputs::{BytesInput, HasTargetBytes, Input, UsesInput}, executors::{Executor, command::CommandConfigurator}, state::{UsesState, HasExecutions}};
use libafl_bolts::AsSlice;
#[derive(Debug)]
struct MyExecutor;

impl CommandConfigurator<BytesInput> for MyExecutor {
   fn spawn_child(
      &mut self,
      input: &BytesInput,
   ) -> Result<Child, Error> {
       let mut command = Command::new("../if");
       command
           .stdin(Stdio::piped())
           .stdout(Stdio::null())
           .stderr(Stdio::null());

       let child = command.spawn().expect("failed to start process");
       let mut stdin = child.stdin.as_ref().unwrap();
       stdin.write_all(input.target_bytes().as_slice())?;
       Ok(child)
   }

   fn exec_timeout(&self) -> Duration {
       Duration::from_secs(5)
   }
}

fn make_executor<EM, Z>() -> impl Executor<EM, Z>
where
   EM: UsesState,
   Z: UsesState<State = EM::State>,
   EM::State: UsesInput<Input = BytesInput> + HasExecutions,
{
   MyExecutor.into_executor(())
}

Required Methods§

source

fn spawn_child(&mut self, input: &I) -> Result<Child, Error>

Spawns a new process with the given configuration.

source

fn exec_timeout(&self) -> Duration

Provides timeout duration for execution of the child process.

Provided Methods§

source

fn stdout_observer(&self) -> Option<Handle<StdOutObserver>>

Get the stdout

source

fn stderr_observer(&self) -> Option<Handle<StdErrObserver>>

Get the stderr

source

fn into_executor<OT, S>(self, observers: OT) -> CommandExecutor<OT, S, Self>
where OT: MatchName,

Create an Executor from this CommandConfigurator.

Object Safety§

This trait is not object safe.

Implementors§