Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean cfgs in executors/command.rs #2735

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 14 additions & 27 deletions libafl/src/executors/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,44 @@ use core::{
marker::PhantomData,
ops::IndexMut,
};
#[cfg(unix)]
use std::os::unix::ffi::OsStrExt;
#[cfg(all(feature = "std", target_os = "linux"))]
#[cfg(target_os = "linux")]
use std::{
ffi::{CStr, CString},
os::fd::AsRawFd,
};
#[cfg(feature = "std")]
use std::{
ffi::{OsStr, OsString},
io::{Read, Write},
os::unix::ffi::OsStrExt,
path::{Path, PathBuf},
process::Child,
process::{Command, Stdio},
process::{Child, Command, Stdio},
time::Duration,
};

#[cfg(all(feature = "std", target_os = "linux"))]
#[cfg(target_os = "linux")]
use libafl_bolts::core_affinity::CoreId;
use libafl_bolts::{
fs::{get_unique_std_input_file, InputFile},
tuples::{Handle, MatchName, RefIndexable},
AsSlice,
};
#[cfg(all(feature = "std", target_os = "linux"))]
#[cfg(target_os = "linux")]
use libc::STDIN_FILENO;
#[cfg(all(feature = "std", target_os = "linux"))]
#[cfg(target_os = "linux")]
use nix::unistd::Pid;
#[cfg(all(feature = "std", target_os = "linux"))]
#[cfg(target_os = "linux")]
use typed_builder::TypedBuilder;

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::{
corpus::Corpus,
executors::{hooks::ExecutorHooksTuple, HasObservers},
inputs::{HasTargetBytes, UsesInput},
executors::{hooks::ExecutorHooksTuple, Executor, ExitKind, HasObservers},
inputs::{HasTargetBytes, Input, UsesInput},
observers::{ObserversTuple, StdErrObserver, StdOutObserver},
state::{HasCorpus, HasExecutions, State, UsesState},
std::borrow::ToOwned,
Error,
};
#[cfg(feature = "std")]
use crate::{inputs::Input, Error};

/// How to deliver input to an external program
/// `StdIn`: The target reads from stdin
Expand Down Expand Up @@ -178,7 +170,7 @@ where
///
/// This configurator was primarly developed to be used in conjunction with
/// [`crate::executors::hooks::intel_pt::IntelPTHook`]
#[cfg(all(feature = "std", target_os = "linux"))]
#[cfg(target_os = "linux")]
#[derive(Debug, Clone, PartialEq, Eq, TypedBuilder)]
pub struct PTraceCommandConfigurator {
#[builder(setter(into))]
Expand All @@ -195,7 +187,7 @@ pub struct PTraceCommandConfigurator {
timeout: u32,
}

#[cfg(all(feature = "std", target_os = "linux"))]
#[cfg(target_os = "linux")]
impl<I> CommandConfigurator<I, Pid> for PTraceCommandConfigurator
where
I: HasTargetBytes,
Expand Down Expand Up @@ -331,7 +323,6 @@ where
}

// 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>
where
S: State + HasExecutions + UsesInput<Input = I>,
Expand Down Expand Up @@ -388,7 +379,6 @@ where
}
}

#[cfg(all(feature = "std", unix))]
impl<EM, OT, S, T, Z> Executor<EM, Z> for CommandExecutor<OT, S, T>
where
EM: UsesState<State = S>,
Expand Down Expand Up @@ -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>
where
EM: UsesState<State = S>,
Expand Down Expand Up @@ -759,8 +749,7 @@ impl CommandExecutorBuilder {

/// A `CommandConfigurator` takes care of creating and spawning a [`Command`] for the [`CommandExecutor`].
/// # 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 libafl::{Error, inputs::{BytesInput, HasTargetBytes, Input, UsesInput}, executors::{Executor, command::CommandConfigurator}, state::{UsesState, HasExecutions}};
/// use libafl_bolts::AsSlice;
Expand Down Expand Up @@ -801,7 +790,6 @@ impl CommandExecutorBuilder {
/// MyExecutor.into_executor(())
/// }
/// ```
#[cfg(all(feature = "std", unix))]
pub trait CommandConfigurator<I, C = Child>: Sized {
/// Get the stdout
fn stdout_observer(&self) -> Option<Handle<StdOutObserver>> {
Expand Down Expand Up @@ -882,7 +870,6 @@ mod tests {
};

#[test]
#[cfg(unix)]
#[cfg_attr(miri, ignore)]
fn test_builder() {
let mut mgr = SimpleEventManager::new(SimpleMonitor::new(|status| {
Expand Down
Loading