Skip to content

Commit 6c2484d

Browse files
committed
Auto merge of #60785 - alexcrichton:error-type-id-destabilize-stable, r=pietroalbini
[stable] 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.
2 parents fc50f32 + bc8787c commit 6c2484d

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

RELEASES.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Version 1.34.2 (2019-05-14)
2+
===========================
3+
4+
* [Destabilize the `Error::type_id` function due to a security
5+
vulnerability][60785]
6+
7+
[60785]: https://github.com/rust-lang/rust/pull/60785
8+
19
Version 1.34.1 (2019-04-25)
210
===========================
311

src/bootstrap/channel.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::Build;
1414
use crate::config::Config;
1515

1616
// The version number
17-
pub const CFG_RELEASE_NUM: &str = "1.34.1";
17+
pub const CFG_RELEASE_NUM: &str = "1.34.2";
1818

1919
pub struct GitInfo {
2020
inner: Option<Info>,

src/libstd/error.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ pub trait Error: Debug + Display {
196196
fn source(&self) -> Option<&(dyn Error + 'static)> { None }
197197

198198
/// Gets the `TypeId` of `self`
199-
#[stable(feature = "error_type_id", since = "1.34.0")]
199+
#[doc(hidden)]
200+
#[unstable(feature = "error_type_id",
201+
reason = "this is memory unsafe to override in user code",
202+
issue = "60784")]
200203
fn type_id(&self) -> TypeId where Self: 'static {
201204
TypeId::of::<Self>()
202205
}

0 commit comments

Comments
 (0)