Skip to main content

resolve_program

Function resolve_program 

Source
pub fn resolve_program(program: &str) -> Result<String, SubprocessError>
Expand description

Resolve a bare program name to an absolute path that is safe to pass to std::process::Command::new.

On Windows, Command::new(bare_name) triggers CreateProcess’s CWD-first executable search — a binary planted in the LSP workspace root would run instead of the legitimate tool (binary-planting RCE, #2764/#3028). This function delegates to the already-hardened resolve_windows_program resolver which searches only absolute PATH directories and excludes the CWD.

§Return value

  • Windows: returns the absolute path of the resolved binary, or Err(SubprocessError) if the program is not found in any absolute PATH directory (fail closed — refusing to run is safer than running a planted binary).
  • Non-Windows: CreateProcess CWD-search semantics do not apply; returns Ok(program.to_string()) unchanged so callers can use this function unconditionally without #[cfg(windows)] guards.

§Usage

let resolved = perl_subprocess_runtime::resolve_program("yath")?;
let mut cmd = std::process::Command::new(resolved);