2020-09-20 05:02:04 -05:00
|
|
|
// This should fail even without validation, but some MIR opts mask the error
|
2022-07-08 11:08:32 -05:00
|
|
|
//@compile-flags: -Zmiri-disable-validation -Zmir-opt-level=0 -Zmiri-permissive-provenance
|
2018-10-12 03:54:37 -05:00
|
|
|
|
2018-07-31 13:27:36 -05:00
|
|
|
static mut LEAK: usize = 0;
|
|
|
|
|
|
|
|
fn fill(v: &mut i32) {
|
2022-06-19 22:33:59 -05:00
|
|
|
unsafe {
|
|
|
|
LEAK = v as *mut _ as usize;
|
|
|
|
}
|
2018-07-31 13:27:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn evil() {
|
2022-07-05 17:16:20 -05:00
|
|
|
unsafe { &mut *(LEAK as *mut i32) }; //~ ERROR is a dangling pointer
|
2018-07-31 13:27:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let _y;
|
|
|
|
{
|
|
|
|
let mut x = 0i32;
|
|
|
|
fill(&mut x);
|
|
|
|
_y = x;
|
|
|
|
}
|
2021-03-22 06:35:30 -05:00
|
|
|
// Now we use a pointer to `x` which is no longer in scope, and thus dead (even though the
|
2022-06-26 20:26:14 -05:00
|
|
|
// `main` stack frame still exists). We even try going through a `usize` for extra sneakiness!
|
2018-07-31 13:27:36 -05:00
|
|
|
evil();
|
|
|
|
}
|