From 11fc57a5d7493756c1dc614035f1d57d4bc9aa18 Mon Sep 17 00:00:00 2001 From: s1341 Date: Thu, 13 Jul 2023 23:50:01 +0300 Subject: [PATCH] Launcher: Allow setting a distinct stderr redirect (#1329) Co-authored-by: Dominik Maier --- libafl/src/bolts/launcher.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libafl/src/bolts/launcher.rs b/libafl/src/bolts/launcher.rs index 8ca869852a..147178d9d2 100644 --- a/libafl/src/bolts/launcher.rs +++ b/libafl/src/bolts/launcher.rs @@ -78,6 +78,10 @@ where /// A file name to write all client output to #[builder(default = None)] stdout_file: Option<&'a str>, + /// A file name to write all client stderr output to. If not specified, output is sent to + /// `stdout_file`. + #[builder(default = None)] + stderr_file: Option<&'a str>, /// The `ip:port` address of another broker to connect our new broker to for multi-machine /// clusters. #[builder(default = None)] @@ -110,6 +114,7 @@ where .field("spawn_broker", &self.spawn_broker) .field("remote_broker_addr", &self.remote_broker_addr) .field("stdout_file", &self.stdout_file) + .field("stderr_file", &self.stderr_file) .finish_non_exhaustive() } } @@ -148,6 +153,10 @@ where let stdout_file = self .stdout_file .map(|filename| File::create(filename).unwrap()); + #[cfg(feature = "std")] + let stderr_file = self + .stderr_file + .map(|filename| File::create(filename).unwrap()); #[cfg(feature = "std")] let debug_output = std::env::var("LIBAFL_DEBUG_OUTPUT").is_ok(); @@ -176,7 +185,11 @@ where if !debug_output { if let Some(file) = stdout_file { dup2(file.as_raw_fd(), libc::STDOUT_FILENO)?; - dup2(file.as_raw_fd(), libc::STDERR_FILENO)?; + if let Some(stderr) = stderr_file { + dup2(stderr.as_raw_fd(), libc::STDERR_FILENO)?; + } else { + dup2(file.as_raw_fd(), libc::STDERR_FILENO)?; + } } }