Clean cfgs in executors/command.rs (#2735)

* clean

* triple tick
This commit is contained in:
Dongjia "toka" Zhang 2024-11-29 19:36:40 +01:00 committed by GitHub
parent bdde109867
commit 2102ae13d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,52 +5,44 @@ use core::{
marker::PhantomData, marker::PhantomData,
ops::IndexMut, ops::IndexMut,
}; };
#[cfg(unix)] #[cfg(target_os = "linux")]
use std::os::unix::ffi::OsStrExt;
#[cfg(all(feature = "std", target_os = "linux"))]
use std::{ use std::{
ffi::{CStr, CString}, ffi::{CStr, CString},
os::fd::AsRawFd, os::fd::AsRawFd,
}; };
#[cfg(feature = "std")]
use std::{ use std::{
ffi::{OsStr, OsString}, ffi::{OsStr, OsString},
io::{Read, Write}, io::{Read, Write},
os::unix::ffi::OsStrExt,
path::{Path, PathBuf}, path::{Path, PathBuf},
process::Child, process::{Child, Command, Stdio},
process::{Command, Stdio},
time::Duration, time::Duration,
}; };
#[cfg(all(feature = "std", target_os = "linux"))] #[cfg(target_os = "linux")]
use libafl_bolts::core_affinity::CoreId; use libafl_bolts::core_affinity::CoreId;
use libafl_bolts::{ use libafl_bolts::{
fs::{get_unique_std_input_file, InputFile}, fs::{get_unique_std_input_file, InputFile},
tuples::{Handle, MatchName, RefIndexable}, tuples::{Handle, MatchName, RefIndexable},
AsSlice, AsSlice,
}; };
#[cfg(all(feature = "std", target_os = "linux"))] #[cfg(target_os = "linux")]
use libc::STDIN_FILENO; use libc::STDIN_FILENO;
#[cfg(all(feature = "std", target_os = "linux"))] #[cfg(target_os = "linux")]
use nix::unistd::Pid; use nix::unistd::Pid;
#[cfg(all(feature = "std", target_os = "linux"))] #[cfg(target_os = "linux")]
use typed_builder::TypedBuilder; use typed_builder::TypedBuilder;
use super::HasTimeout; use super::HasTimeout;
#[cfg(all(feature = "std", unix))]
use crate::executors::Executor;
#[cfg(all(feature = "std", any(unix, doc)))]
use crate::executors::ExitKind;
use crate::{ use crate::{
corpus::Corpus, corpus::Corpus,
executors::{hooks::ExecutorHooksTuple, HasObservers}, executors::{hooks::ExecutorHooksTuple, Executor, ExitKind, HasObservers},
inputs::{HasTargetBytes, UsesInput}, inputs::{HasTargetBytes, Input, UsesInput},
observers::{ObserversTuple, StdErrObserver, StdOutObserver}, observers::{ObserversTuple, StdErrObserver, StdOutObserver},
state::{HasCorpus, HasExecutions, State, UsesState}, state::{HasCorpus, HasExecutions, State, UsesState},
std::borrow::ToOwned, std::borrow::ToOwned,
Error,
}; };
#[cfg(feature = "std")]
use crate::{inputs::Input, Error};
/// How to deliver input to an external program /// How to deliver input to an external program
/// `StdIn`: The target reads from stdin /// `StdIn`: The target reads from stdin
@ -178,7 +170,7 @@ where
/// ///
/// This configurator was primarly developed to be used in conjunction with /// This configurator was primarly developed to be used in conjunction with
/// [`crate::executors::hooks::intel_pt::IntelPTHook`] /// [`crate::executors::hooks::intel_pt::IntelPTHook`]
#[cfg(all(feature = "std", target_os = "linux"))] #[cfg(target_os = "linux")]
#[derive(Debug, Clone, PartialEq, Eq, TypedBuilder)] #[derive(Debug, Clone, PartialEq, Eq, TypedBuilder)]
pub struct PTraceCommandConfigurator { pub struct PTraceCommandConfigurator {
#[builder(setter(into))] #[builder(setter(into))]
@ -195,7 +187,7 @@ pub struct PTraceCommandConfigurator {
timeout: u32, timeout: u32,
} }
#[cfg(all(feature = "std", target_os = "linux"))] #[cfg(target_os = "linux")]
impl<I> CommandConfigurator<I, Pid> for PTraceCommandConfigurator impl<I> CommandConfigurator<I, Pid> for PTraceCommandConfigurator
where where
I: HasTargetBytes, I: HasTargetBytes,
@ -331,7 +323,6 @@ where
} }
// this only works on unix because of the reliance on checking the process signal for detecting OOM // this only works on unix because of the reliance on checking the process signal for detecting OOM
#[cfg(all(feature = "std", unix))]
impl<I, OT, S, T> CommandExecutor<OT, S, T> impl<I, OT, S, T> CommandExecutor<OT, S, T>
where where
S: State + HasExecutions + UsesInput<Input = I>, S: State + HasExecutions + UsesInput<Input = I>,
@ -388,7 +379,6 @@ where
} }
} }
#[cfg(all(feature = "std", unix))]
impl<EM, OT, S, T, Z> Executor<EM, Z> for CommandExecutor<OT, S, T> impl<EM, OT, S, T, Z> Executor<EM, Z> for CommandExecutor<OT, S, T>
where where
EM: UsesState<State = S>, EM: UsesState<State = S>,
@ -425,7 +415,7 @@ where
} }
} }
#[cfg(all(feature = "std", target_os = "linux"))] #[cfg(target_os = "linux")]
impl<EM, OT, S, T, Z, HT> Executor<EM, Z> for CommandExecutor<OT, S, T, HT, Pid> impl<EM, OT, S, T, Z, HT> Executor<EM, Z> for CommandExecutor<OT, S, T, HT, Pid>
where where
EM: UsesState<State = S>, EM: UsesState<State = S>,
@ -759,8 +749,7 @@ impl CommandExecutorBuilder {
/// A `CommandConfigurator` takes care of creating and spawning a [`Command`] for the [`CommandExecutor`]. /// A `CommandConfigurator` takes care of creating and spawning a [`Command`] for the [`CommandExecutor`].
/// # Example /// # Example
#[cfg_attr(all(feature = "std", unix), doc = " ```")] /// ```
#[cfg_attr(not(all(feature = "std", unix)), doc = " ```ignore")]
/// use std::{io::Write, process::{Stdio, Command, Child}, time::Duration}; /// 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::{Error, inputs::{BytesInput, HasTargetBytes, Input, UsesInput}, executors::{Executor, command::CommandConfigurator}, state::{UsesState, HasExecutions}};
/// use libafl_bolts::AsSlice; /// use libafl_bolts::AsSlice;
@ -801,7 +790,6 @@ impl CommandExecutorBuilder {
/// MyExecutor.into_executor(()) /// MyExecutor.into_executor(())
/// } /// }
/// ``` /// ```
#[cfg(all(feature = "std", unix))]
pub trait CommandConfigurator<I, C = Child>: Sized { pub trait CommandConfigurator<I, C = Child>: Sized {
/// Get the stdout /// Get the stdout
fn stdout_observer(&self) -> Option<Handle<StdOutObserver>> { fn stdout_observer(&self) -> Option<Handle<StdOutObserver>> {
@ -882,7 +870,6 @@ mod tests {
}; };
#[test] #[test]
#[cfg(unix)]
#[cfg_attr(miri, ignore)] #[cfg_attr(miri, ignore)]
fn test_builder() { fn test_builder() {
let mut mgr = SimpleEventManager::new(SimpleMonitor::new(|status| { let mut mgr = SimpleEventManager::new(SimpleMonitor::new(|status| {