Skip to content

Commit 479c06b

Browse files
committed
Refine EXEC_PATH validation in spawn_git_daemon
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.
1 parent da03932 commit 479c06b

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Diff for: tests/tools/src/lib.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,19 @@ pub fn run_git(working_dir: &Path, args: &[&str]) -> std::io::Result<std::proces
187187
/// Spawn a git daemon process to host all repository at or below `working_dir`.
188188
pub fn spawn_git_daemon(working_dir: impl AsRef<Path>) -> std::io::Result<GitDaemon> {
189189
static EXEC_PATH: Lazy<PathBuf> = Lazy::new(|| {
190-
let path = std::process::Command::new(GIT_PROGRAM)
190+
let output = std::process::Command::new(GIT_PROGRAM)
191191
.arg("--exec-path")
192-
.stderr(std::process::Stdio::null())
193192
.output()
194-
.expect("can execute `git --exec-path`")
195-
.stdout;
196-
String::from_utf8(path.trim().into())
197-
.expect("no invalid UTF8 in exec-path")
193+
.expect("can execute `git --exec-path`");
194+
195+
assert!(output.status.success(), "`git --exec-path` failed");
196+
197+
output
198+
.stdout
199+
.strip_suffix(b"\n")
200+
.expect("malformed output from `git --exec-path`")
201+
.to_os_str()
202+
.expect("no invalid UTF-8 in `--exec-path` except as OS allows")
198203
.into()
199204
});
200205
let mut ports: Vec<_> = (9419u16..9419 + 100).collect();

0 commit comments

Comments
 (0)