about summary refs log tree commit diff
path: root/src/libstd/error.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2019-05-13 08:14:02 -0700
committerAlex Crichton <alex@alexcrichton.com>2019-05-13 08:18:37 -0700
commitc47e2ef8d49f0140086d187ee3528a50454be394 (patch)
treea1049ab551f7e5a7caa516efc3ad8852bd197dd4 /src/libstd/error.rs
parenta9ec99f4201ec33026a468ef1289f98a95b4d71a (diff)
downloadrust-c47e2ef8d49f0140086d187ee3528a50454be394.tar.gz
rust-c47e2ef8d49f0140086d187ee3528a50454be394.zip
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
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 #60784.
Diffstat (limited to 'src/libstd/error.rs')
-rw-r--r--src/libstd/error.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/libstd/error.rs b/src/libstd/error.rs
index 081fff0562b..7cb830e751a 100644
--- a/src/libstd/error.rs
+++ b/src/libstd/error.rs
@@ -197,7 +197,10 @@ pub trait Error: Debug + Display {
     fn source(&self) -> Option<&(dyn Error + 'static)> { None }
 
     /// Gets the `TypeId` of `self`
-    #[stable(feature = "error_type_id", since = "1.34.0")]
+    #[doc(hidden)]
+    #[unstable(feature = "error_type_id",
+               reason = "this is memory unsafe to override in user code",
+               issue = "60784")]
     fn type_id(&self) -> TypeId where Self: 'static {
         TypeId::of::<Self>()
     }