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

Launcher: Allow setting a distinct stderr redirect #1329

Merged
merged 3 commits into from
Jul 13, 2023
Merged
Changes from 1 commit
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
15 changes: 14 additions & 1 deletion libafl/src/bolts/launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably also happen when debug_output is set(?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If debug_output is true, the redirect won't happen, not sure if that's what we want?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if debug_output is true, we're supposed to ignore the stdout/stderr redirections and just let things go to original stdout/stderr, no?

}
}
}

Expand Down
Loading