-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.Category: This is a bug.F-return_position_impl_trait_in_trait`#![feature(return_position_impl_trait_in_trait)]``#![feature(return_position_impl_trait_in_trait)]`I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityHigh priorityT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
I tried this code:
use std::sync::Mutex;
static MUTEX: Mutex<Option<&'static str>> = Mutex::new(None);
trait Foo {
fn foo<'a: 'static>(&self) -> impl Sized;
}
impl Foo for str {
fn foo<'a: 'static>(&'a self) -> impl Sized + 'a {
*MUTEX.lock().unwrap() = Some(self);
}
}
fn call_foo<T: Foo + ?Sized>(s: &T) {
s.foo();
}
fn main() {
let s = String::from("hello, world");
call_foo(s.as_str());
drop(s);
println!("> {}", MUTEX.lock().unwrap().unwrap());
}
I expected to see this happen: Compilation failure.
Instead, this happened: Segfault due to UAF
Why?
See comment below.
Meta
rustc --version --verbose
:
2024-11-24
Not present on beta or stable.
Metadata
Metadata
Assignees
Labels
A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.Category: This is a bug.F-return_position_impl_trait_in_trait`#![feature(return_position_impl_trait_in_trait)]``#![feature(return_position_impl_trait_in_trait)]`I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityHigh priorityT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Type
Projects
Status
Completed