Skip to content

rustup toolchain link with special characters in the toolchain name causes panics #3517

@majaha

Description

@majaha

I found that using special characters in the rustup toolchain link command can cause panics:

matt@Matts-PC:~/rust$ rustup toolchain link "foo(bar)" ~/rust/build/host/stage0/
matt@Matts-PC:~/rust$ RUST_BACKTRACE=1 rustup toolchain list
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error("unexpected character in pre-release identifier")', src/utils/utils.rs:549:83
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/panicking.rs:64:14
   2: core::result::unwrap_failed
             at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/result.rs:1790:5
   3: rustup::utils::utils::toolchain_sort::special_version
   4: rustup::utils::utils::toolchain_sort::toolchain_sort_key
   5: alloc::slice::<impl [T]>::sort_by::{{closure}}
   6: rustup::config::Cfg::list_toolchains
   7: rustup::cli::rustup_mode::toolchain_list
   8: rustup::cli::rustup_mode::main
   9: rustup_init::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
matt@Matts-PC:~/rust$

I also got similar results with "foo#bar"

I'd assume the problem is that rustup toolchain link needs to sanitise it's input more thoroughly.

This was tested on rustup 1.26.0 (5af9b9484 2023-04-05)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions