Skip to content

Commit fba34dc

Browse files
committed
Stop defaulting to $PATH searches when the binary can't be found and causing infinite recursion
1 parent 4381291 commit fba34dc

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/rustup/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ error_chain! {
2222
description("toolchain is not installed")
2323
display("toolchain '{}' is not installed", t)
2424
}
25+
BinaryNotFound(t: String, bin: String) {
26+
description("toolchain does not contain binary")
27+
display("toolchain '{}' does not have the binary `{}`", t, bin)
28+
}
2529
NeedMetadataUpgrade {
2630
description("rustup's metadata is out of date. run `rustup self upgrade-data`")
2731
}

src/rustup/toolchain.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,20 @@ impl<'a> Toolchain<'a> {
301301
};
302302

303303
let bin_path = self.path.join("bin").join(&binary);
304-
let mut cmd = Command::new(if utils::is_file(&bin_path) {
304+
let path = if utils::is_file(&bin_path) {
305305
&bin_path
306306
} else {
307-
// If the bin doesn't actually exist in the sysroot, let the OS try
308-
// to resolve it globally for us
307+
let recursion_count = env::var("RUST_RECURSION_COUNT").ok()
308+
.and_then(|s| s.parse().ok()).unwrap_or(0);
309+
if recursion_count > 4 {
310+
return Err(ErrorKind::BinaryNotFound(self.name.clone(),
311+
binary.to_string_lossy()
312+
.into())
313+
.into())
314+
}
309315
Path::new(&binary)
310-
});
316+
};
317+
let mut cmd = Command::new(&path);
311318
self.set_env(&mut cmd);
312319
Ok(cmd)
313320
}

0 commit comments

Comments
 (0)