Uh oh!
There was an error while loading. Please reload this page.
Destabilize the Error::type_id function - #60787
Conversation
This commit destabilizes the `Error::type_id` function in the standard library. This does so by effectively reverting rust-lang#58048, restoring the `#[unstable]` attribute. The security mailing list has recently been notified of a vulnerability relating to the stabilization of this function. First stabilized in Rust 1.34.0, a stable function here allows users to implement a custom return value for this function: struct MyType; impl Error for MyType { fn type_id(&self) -> TypeId { // Enable safe casting to `String` by accident. TypeId::of::<String>() } } This, when combined with the `Error::downcast` family of functions, allows safely casting a type to any other type, clearly a memory safety issue! A security announcement will be shortly posted to the security mailing list as well as the Rust Blog, and when those links are available they'll be filled in for this PR as well. This commit simply destabilizes the `Error::type_id` which, although breaking for users since Rust 1.34.0, is hoped to have little impact and has been deemed sufficient to mitigate this issue for the stable channel. The long-term fate of the `Error::type_id` API will be discussed at rust-lang#60784.
rust-highfive
commented
May 13, 2019
r? @KodrAus (rust_highfive has picked a reviewer for you, use r? to override) |
alexcrichton
commented
May 13, 2019
emilyalbini
commented
May 13, 2019
@bors r+ p=500 |
bors
commented
May 13, 2019
📌 Commit 3db667a has been approved by |
strega-nil
commented
May 13, 2019
Is there something wrong with making it an |
sfackler
commented
May 13, 2019
@ubsan Making the |
strega-nil
commented
May 13, 2019
@sfackler oh, I see, right; you want it to only be unsafe to write the function |
So it'd be better to have something on the order of unsafetraitTypeInfo{fntype_id(&self) -> TypeId;}impl<T: ?Sized>TypeInfoforT{fntype_id(&self) -> TypeId{TypeId::of::<Self>()}}traitError:TypeInfo{} |
bors
commented
May 13, 2019
⌛ Testing commit 3db667a with merge 291ea7569bf6e6aa63b7312c51c7489632f7bb63... |
bors
commented
May 14, 2019
💔 Test failed - checks-travis |
rust-highfive
commented
May 14, 2019
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The proposed use std::any::TypeId;use std::fmt::{Debug,Display};traitTypeInfo{fntype_id(&self) -> TypeIdwhereSelf:'static;}impl<T: ?Sized>TypeInfoforT{fntype_id(&self) -> TypeIdwhereT:'static,{TypeId::of::<Self>()}}traitError:Debug + Display + TypeInfo{fndescription(&self) -> &str{"description() is deprecated; use Display"}fncause(&self) -> Option<&dynError>{self.source()}fnsource(&self) -> Option<&(dynError + 'static)>{None}}Also, one thing I feel like Rust is missing is being able to declare a trait method as unsafe to implement. |
emilyalbini
commented
May 14, 2019
bors
commented
May 14, 2019
… r=pietroalbini Destabilize the `Error::type_id` function This commit destabilizes the `Error::type_id` function in the standard library. This does so by effectively reverting #58048, restoring the `#[unstable]` attribute. The security mailing list has recently been notified of a vulnerability relating to the stabilization of this function. First stabilized in Rust 1.34.0, a stable function here allows users to implement a custom return value for this function: struct MyType; impl Error for MyType { fn type_id(&self) -> TypeId { // Enable safe casting to `String` by accident. TypeId::of::<String>() } } This, when combined with the `Error::downcast` family of functions, allows safely casting a type to any other type, clearly a memory safety issue! A formal announcement has been made to the [security mailing list](https://groups.google.com/forum/#!topic/rustlang-security-announcements/aZabeCMUv70) as well as [the blog](https://blog.rust-lang.org/2019/05/13/Security-advisory.html) This commit simply destabilizes the `Error::type_id` which, although breaking for users since Rust 1.34.0, is hoped to have little impact and has been deemed sufficient to mitigate this issue for the stable channel. The long-term fate of the `Error::type_id` API will be discussed at #60784.
bors
commented
May 14, 2019
💥 Test timed out |
emilyalbini
commented
May 14, 2019
@bors retry |
bors
commented
May 14, 2019
… r=pietroalbini Destabilize the `Error::type_id` function This commit destabilizes the `Error::type_id` function in the standard library. This does so by effectively reverting #58048, restoring the `#[unstable]` attribute. The security mailing list has recently been notified of a vulnerability relating to the stabilization of this function. First stabilized in Rust 1.34.0, a stable function here allows users to implement a custom return value for this function: struct MyType; impl Error for MyType { fn type_id(&self) -> TypeId { // Enable safe casting to `String` by accident. TypeId::of::<String>() } } This, when combined with the `Error::downcast` family of functions, allows safely casting a type to any other type, clearly a memory safety issue! A formal announcement has been made to the [security mailing list](https://groups.google.com/forum/#!topic/rustlang-security-announcements/aZabeCMUv70) as well as [the blog](https://blog.rust-lang.org/2019/05/13/Security-advisory.html) This commit simply destabilizes the `Error::type_id` which, although breaking for users since Rust 1.34.0, is hoped to have little impact and has been deemed sufficient to mitigate this issue for the stable channel. The long-term fate of the `Error::type_id` API will be discussed at #60784.
bors
commented
May 14, 2019
☀️ Test successful - checks-travis, status-appveyor |
This commit destabilizes the
Error::type_idfunction in the standard library.This does so by effectively reverting #58048, restoring the
#[unstable]attribute. The security mailing list has recently been notified of a
vulnerability relating to the stabilization of this function. First stabilized
in Rust 1.34.0, a stable function here allows users to implement a custom
return value for this function:
This, when combined with the
Error::downcastfamily of functions, allowssafely casting a type to any other type, clearly a memory safety issue! A
formal announcement has been made to the security mailing list as well as the blog
This commit simply destabilizes the
Error::type_idwhich, although breakingfor users since Rust 1.34.0, is hoped to have little impact and has been deemed
sufficient to mitigate this issue for the stable channel. The long-term fate of
the
Error::type_idAPI will be discussed at #60784.