Skip to content

feat(self_update): add proxy sanity checks #4338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,29 @@ fn install_proxies_with_opts(process: &Process, force_hard_links: bool) -> Resul
Ok(())
}

fn check_proxy_sanity(process: &Process, components: &[&str], desc: &ToolchainDesc) -> Result<()> {
let bin_path = process.cargo_home()?.join("bin");

// Sometimes linking a proxy produces an unpredictable result, where the proxy
// is in place, but manages to not call rustup correctly. One way to make sure we
// don't run headfirst into the wall is to at least try and run our freshly
// installed proxies, to see if they return some manner of reasonable output.
// We limit ourselves to the most common two installed components (cargo and rustc),
// because their binary names also happen to match up, which is not necessarily
// a given.
for component in components.iter().filter(|c| ["cargo", "rustc"].contains(c)) {
let cmd = Command::new(bin_path.join(format!("{component}{EXE_SUFFIX}")))
.args([&format!("+{desc}"), "--version"])
.status();

if !cmd.is_ok_and(|status| status.success()) {
return Err(RustupError::BrokenProxy.into());
}
}

Ok(())
}

async fn maybe_install_rust(
current_dir: PathBuf,
quiet: bool,
Expand Down Expand Up @@ -907,6 +930,8 @@ async fn maybe_install_rust(
.0
};

check_proxy_sanity(process, components, desc)?;

cfg.set_default(Some(&desc.into()))?;
writeln!(process.stdout().lock())?;
common::show_channel_update(&cfg, PackageUpdate::Toolchain(desc.clone()), Ok(status))?;
Expand Down
6 changes: 6 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ pub enum RustupError {
target: TargetTriple,
suggestion: Option<String>,
},
#[error(
"rustup executable proxies don't seem to work\n\
help: this might be a bug in rustup, please open a new issue here:\n\
help: https://github.com/rust-lang/rustup/issues/new"
)]
BrokenProxy,
#[error("unknown metadata version: '{0}'")]
UnknownMetadataVersion(String),
#[error("manifest version '{0}' is not supported")]
Expand Down
Loading