Skip to content

Commit

Permalink
Refine EXEC_PATH validation in spawn_git_daemon
Browse files Browse the repository at this point in the history
This enforces requirements more precisely and, overall, more
robustly, when validating and converting `git --exec-path` output
to a `PathBuf`.

This also no longer redirect standard error to the null device when
running that command. No stderr output is expected; if there is any
such output, it's better seen than thrown away.
  • Loading branch information
EliahKagan committed Nov 30, 2024
1 parent da03932 commit 479c06b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions tests/tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,19 @@ pub fn run_git(working_dir: &Path, args: &[&str]) -> std::io::Result<std::proces
/// Spawn a git daemon process to host all repository at or below `working_dir`.
pub fn spawn_git_daemon(working_dir: impl AsRef<Path>) -> std::io::Result<GitDaemon> {
static EXEC_PATH: Lazy<PathBuf> = Lazy::new(|| {
let path = std::process::Command::new(GIT_PROGRAM)
let output = std::process::Command::new(GIT_PROGRAM)
.arg("--exec-path")
.stderr(std::process::Stdio::null())
.output()
.expect("can execute `git --exec-path`")
.stdout;
String::from_utf8(path.trim().into())
.expect("no invalid UTF8 in exec-path")
.expect("can execute `git --exec-path`");

assert!(output.status.success(), "`git --exec-path` failed");

output
.stdout
.strip_suffix(b"\n")
.expect("malformed output from `git --exec-path`")
.to_os_str()
.expect("no invalid UTF-8 in `--exec-path` except as OS allows")
.into()
});
let mut ports: Vec<_> = (9419u16..9419 + 100).collect();
Expand Down

0 comments on commit 479c06b

Please sign in to comment.