Skip to content

Commit

Permalink
Merge pull request #52 from orhun/fix/canonicalize_binary
Browse files Browse the repository at this point in the history
fix: use the canonicalized binary path if possible
  • Loading branch information
JakWai01 committed Sep 24, 2024
2 parents d5dd5b4 + 7743e73 commit e4e36c7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ use nix::sys::signal::Signal;
use nix::sys::wait::{wait, WaitStatus};
use nix::unistd::Pid;
use std::collections::HashMap;
use std::fs;
use std::io::Write;
use std::os::unix::process::CommandExt;
use std::process::{Command, Stdio};
Expand Down Expand Up @@ -470,8 +471,17 @@ impl<W: Write> Tracer<W> {
pub fn run_tracee(command: &[String], envs: &[String], username: &Option<String>) -> Result<()> {
ptrace::traceme()?;
personality(ADDR_NO_RANDOMIZE).map_err(|_| anyhow!("Unable to set ADDR_NO_RANDOMIZE"))?;

let mut cmd = Command::new(command.get(0).ok_or_else(|| anyhow!("No command"))?);
let mut binary = command
.get(0)
.ok_or_else(|| anyhow!("No command"))?
.to_string();
if let Ok(bin) = fs::canonicalize(&binary) {
binary = bin
.to_str()
.ok_or_else(|| anyhow!("Invalid binary path"))?
.to_string()
}
let mut cmd = Command::new(binary);
cmd.args(command[1..].iter()).stdout(Stdio::null());

for token in envs {
Expand Down

0 comments on commit e4e36c7

Please sign in to comment.