Skip to content

Commit 1fd74eb

Browse files
committed
Auto merge of #50374 - petrochenkov:pypath, r=Mark-Simulacrum
rustbuild: Normalize paths coming from Python slightly Fixes #49785
2 parents 4d7bbdd + 993f7c5 commit 1fd74eb

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/bootstrap/config.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,14 @@ struct TomlTarget {
325325
}
326326

327327
impl Config {
328+
fn path_from_python(var_key: &str) -> PathBuf {
329+
match env::var_os(var_key) {
330+
// Do not trust paths from Python and normalize them slightly (#49785).
331+
Some(var_val) => Path::new(&var_val).components().collect(),
332+
_ => panic!("expected '{}' to be set", var_key),
333+
}
334+
}
335+
328336
pub fn default_opts() -> Config {
329337
let mut config = Config::default();
330338
config.llvm_enabled = true;
@@ -348,9 +356,9 @@ impl Config {
348356
config.deny_warnings = true;
349357

350358
// set by bootstrap.py
351-
config.src = env::var_os("SRC").map(PathBuf::from).expect("'SRC' to be set");
352359
config.build = INTERNER.intern_str(&env::var("BUILD").expect("'BUILD' to be set"));
353-
config.out = env::var_os("BUILD_DIR").map(PathBuf::from).expect("'BUILD_DIR' set");
360+
config.src = Config::path_from_python("SRC");
361+
config.out = Config::path_from_python("BUILD_DIR");
354362

355363
let stage0_root = config.out.join(&config.build).join("stage0/bin");
356364
config.initial_rustc = stage0_root.join(exe("rustc", &config.build));

0 commit comments

Comments
 (0)