diff --git a/libafl/src/bolts/launcher.rs b/libafl/src/bolts/launcher.rs index 1841ca7d97..909a2e8c97 100644 --- a/libafl/src/bolts/launcher.rs +++ b/libafl/src/bolts/launcher.rs @@ -18,7 +18,7 @@ use crate::bolts::os::startable_self; use crate::bolts::os::{dup2, fork, ForkResult}; #[cfg(all(unix, feature = "std"))] -use std::ffi::CString; +use std::{fs::File, os::unix::io::AsRawFd}; #[cfg(feature = "std")] use std::net::SocketAddr; @@ -98,16 +98,6 @@ where let mut handles = vec![]; println!("spawning on cores: {:?}", self.cores); - let file = self.stdout_file.map(|filename| { - let fname = CString::new(filename).unwrap(); - unsafe { - libc::open( - fname.as_ptr(), - libc::O_WRONLY | libc::O_CREAT | libc::O_TRUNC, - 0666, - ) - } - }); // Spawn clients for (index, (id, bind_to)) in core_ids.iter().enumerate().take(num_cores).enumerate() { @@ -128,10 +118,10 @@ where std::thread::sleep(std::time::Duration::from_secs((index + 1) as u64)); #[cfg(feature = "std")] - if let Some(fd) = file { - dup2(fd, libc::STDOUT_FILENO)?; - dup2(fd, libc::STDERR_FILENO)?; - unsafe { libc::close(fd) }; + if let Some(filename) = self.stdout_file { + let file = File::create(filename).unwrap(); + dup2(file.as_raw_fd(), libc::STDOUT_FILENO)?; + dup2(file.as_raw_fd(), libc::STDERR_FILENO)?; } // Fuzzer client. keeps retrying the connection to broker till the broker starts let (state, mgr) = RestartingMgr::::builder()