Skip to content

Commit 24c11ac

Browse files
committed
Test that empty EXEPATH doesn't trigger the optimization
The `EXEPATH` optimization in `system_prefix()` on Windows relies on `EXEPATH` either being unset or set to a value where it is okay to attempt to find and use `clangarm64`, `mingw64`, and `mingw32` subdirectories. Like most environment variables, `EXEPATH` is unlikely to be directly controllable by an attacker. But it may exist with a different meaning from any we (and Git for Windows) intend. It also may inadvertently be set to an empty string, or intnetionally set to a relative path; in either case, we cannot safely use it for the `EXEPATH` optimization in `system_prefix()`. In particular, if it is an empty string, then an attempt would be made to use a `clangarm64`, `mingw64`, or `mingw32` subdirectory of the current working directory. This test will fail until the `EXEPATH` optimization is refined to bail out--and fall back to the more robust strategy--if `EXEPATH` is an empty string, or under broader conditions such as it not being an absolute path.
1 parent 5ac8cff commit 24c11ac

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

gix-path/src/env/tests.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod system_prefix {
22
use super::super::system_prefix_from_exepath_var;
33
use gix_testtools::tempfile;
4+
use serial_test::serial;
45
use std::{ffi::OsString, path::PathBuf};
56

67
struct ExePath {
@@ -104,4 +105,19 @@ mod system_prefix {
104105
assert_eq!(outcome, None);
105106
}
106107
}
108+
109+
#[test]
110+
#[serial]
111+
fn exepath_empty_string() {
112+
for name in ["mingw32", "mingw64", "clangarm64"] {
113+
let exepath = ExePath::new();
114+
exepath.create_subdir(name);
115+
let _cwd = gix_testtools::set_current_dir(&exepath.path).expect("can change to test dir");
116+
let outcome = system_prefix_from_exepath_var(|key| match key {
117+
"EXEPATH" => Some("".into()),
118+
_ => None,
119+
});
120+
assert_eq!(outcome, None);
121+
}
122+
}
107123
}

0 commit comments

Comments
 (0)