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:
Not present on beta or stable.
I tried this code:
I expected to see this happen: Compilation failure.
Instead, this happened: Segfault due to UAF
Why?
See comment below.
Meta
rustc --version --verbose:Not present on beta or stable.