Open
Description
The following function may seem sound:
fn definitely_safe(b: bool) {
static mut S: i32 = 0;
struct Bomb<'a>(&'a mut i32);
impl<'a> Drop for Bomb<'a> {
fn drop(&mut self) {
*self.0 = 42;
}
}
// SAEFTY: we're not creating a second reference while
// this one is live.
let _bomb = Bomb(unsafe { &mut *ptr::addr_of_mut!(S) });
if b {
panic!("Oopsie, something went wrong!");
}
}
But actually it is not. The panic can call arbitrary user-defined code via a panic hook, and that can do a reentrant call do definitely_safe
, and then we have UB.
I don't think there is any way to say that definitely_safe
is sound, so the main question is -- how to we raise awareness of this reentrancy issue so that unsafe code authors don't stumble into it?
Metadata
Metadata
Assignees
Labels
No labels