From 993f7c5715743600e924c5e90c5bff7a64879063 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 1 May 2018 21:25:38 +0300 Subject: [PATCH] rustbuild: Normalize paths coming from Python slightly Fixes #49785 --- src/bootstrap/config.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 1b4b2c5fb2a54..7175f6a67642b 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -325,6 +325,14 @@ struct TomlTarget { } impl Config { + fn path_from_python(var_key: &str) -> PathBuf { + match env::var_os(var_key) { + // Do not trust paths from Python and normalize them slightly (#49785). + Some(var_val) => Path::new(&var_val).components().collect(), + _ => panic!("expected '{}' to be set", var_key), + } + } + pub fn default_opts() -> Config { let mut config = Config::default(); config.llvm_enabled = true; @@ -348,9 +356,9 @@ impl Config { config.deny_warnings = true; // set by bootstrap.py - config.src = env::var_os("SRC").map(PathBuf::from).expect("'SRC' to be set"); config.build = INTERNER.intern_str(&env::var("BUILD").expect("'BUILD' to be set")); - config.out = env::var_os("BUILD_DIR").map(PathBuf::from).expect("'BUILD_DIR' set"); + config.src = Config::path_from_python("SRC"); + config.out = Config::path_from_python("BUILD_DIR"); let stage0_root = config.out.join(&config.build).join("stage0/bin"); config.initial_rustc = stage0_root.join(exe("rustc", &config.build));