Skip to content

Commit

Permalink
refactor/ptrace: use safe dup2
Browse files Browse the repository at this point in the history
  • Loading branch information
kxxt committed Feb 23, 2025
1 parent 50c893b commit a2b6735
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/ptrace/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ use enumflags2::BitFlags;
use inspect::{read_arcstr, read_output_msg_array};
use nix::{
errno::Errno,
libc::{self, AT_EMPTY_PATH, S_ISGID, S_ISUID, c_int, dup2, pthread_self, pthread_setname_np},
libc::{self, AT_EMPTY_PATH, S_ISGID, S_ISUID, c_int, pthread_self, pthread_setname_np},
sys::{ptrace::AddressType, stat::fstat, wait::WaitPidFlag},
unistd::{
Gid, Pid, Uid, User, getpid, initgroups, setpgid, setresgid, setresuid, setsid, tcsetpgrp,
Gid, Pid, Uid, User, dup2, getpid, initgroups, setpgid, setresgid, setresuid, setsid, tcsetpgrp,
},
};
use state::{PendingDetach, Syscall};
Expand Down Expand Up @@ -238,12 +238,10 @@ impl Tracer {
}

if !with_tty {
unsafe {
let dev_null = std::fs::File::open("/dev/null")?;
dup2(dev_null.as_raw_fd(), 0);
dup2(dev_null.as_raw_fd(), 1);
dup2(dev_null.as_raw_fd(), 2);
}
let dev_null = std::fs::File::open("/dev/null")?;
dup2(dev_null.as_raw_fd(), 0).unwrap();
dup2(dev_null.as_raw_fd(), 1).unwrap();
dup2(dev_null.as_raw_fd(), 2).unwrap();
}

if use_pseudo_term {
Expand Down

0 comments on commit a2b6735

Please sign in to comment.