Skip to content

Commit

Permalink
Only absolutize exe if abs path refers to a file and is executable
Browse files Browse the repository at this point in the history
  • Loading branch information
avdv committed Jun 4, 2024
1 parent f593f4c commit 31eeae9
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/buck2_forkserver/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod process_group;
pub mod status_decoder;

use std::borrow::Cow;
use std::fs;
use std::path::Path;
use std::pin::Pin;
use std::process::Command;
Expand Down Expand Up @@ -353,7 +354,20 @@ pub fn maybe_absolutize_exe<'a>(

let abs = spawned_process_cwd.join(exe);
if fs_util::try_exists(&abs).context("Error absolute-izing executable")? {
return Ok(abs.into_path_buf().into());
let metadata = fs::metadata(&abs).context("Error getting metadata for path")?;
if metadata.is_file() {
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
if metadata.permissions().mode() & 0o111 != 0 {
return Ok(abs.into_path_buf().into());
}
}
#[cfg(not(unix))]
{
return Ok(abs.into_path_buf().into());
}
}
}

Ok(exe.into())
Expand Down

0 comments on commit 31eeae9

Please sign in to comment.