This commit is contained in:
Ralf Jung 2022-07-24 08:37:29 -04:00
parent 8fdb720329
commit c33fc24566
5 changed files with 11 additions and 23 deletions

View File

@ -1 +1 @@
41419e70366962c9a878bfe673ef4df38db6f7f1
35a061724802377a21fc6dac1ebcbb9b8d1f558a

View File

@ -1,6 +1,5 @@
// Some optimizations remove ZST accesses, thus masking this UB.
//@compile-flags: -Zmir-opt-level=0
//@error-pattern: memory access failed: null pointer is a dangling pointer
#[allow(deref_nullptr)]
fn main() {
@ -8,4 +7,5 @@ fn main() {
// Also not assigning directly as that's array initialization, not assignment.
let zst_val = [1u8; 0];
unsafe { std::ptr::null_mut::<[u8; 0]>().write(zst_val) };
//~^ERROR: memory access failed: null pointer is a dangling pointer
}

View File

@ -1,19 +1,13 @@
error: Undefined Behavior: memory access failed: null pointer is a dangling pointer (it has no provenance)
--> RUSTLIB/core/src/ptr/mod.rs:LL:CC
--> $DIR/null_pointer_write_zst.rs:LL:CC
|
LL | copy_nonoverlapping(&src as *const T, dst, 1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: null pointer is a dangling pointer (it has no provenance)
LL | unsafe { std::ptr::null_mut::<[u8; 0]>().write(zst_val) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: null pointer is a dangling pointer (it has no provenance)
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: inside `std::ptr::write::<[u8; 0]>` at RUSTLIB/core/src/ptr/mod.rs:LL:CC
= note: inside `std::ptr::mut_ptr::<impl *mut [u8; 0]>::write` at RUSTLIB/core/src/ptr/mut_ptr.rs:LL:CC
note: inside `main` at $DIR/null_pointer_write_zst.rs:LL:CC
--> $DIR/null_pointer_write_zst.rs:LL:CC
|
LL | unsafe { std::ptr::null_mut::<[u8; 0]>().write(zst_val) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: inside `main` at $DIR/null_pointer_write_zst.rs:LL:CC
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

View File

@ -1,9 +1,9 @@
//@error-pattern: overflow computing total size of `write_bytes`
use std::mem;
fn main() {
let mut y = 0;
unsafe {
(&mut y as *mut i32).write_bytes(0u8, 1usize << (mem::size_of::<usize>() * 8 - 1));
//~^ ERROR: overflow computing total size of `write_bytes`
}
}

View File

@ -1,19 +1,13 @@
error: Undefined Behavior: overflow computing total size of `write_bytes`
--> RUSTLIB/core/src/intrinsics.rs:LL:CC
--> $DIR/write_bytes_overflow.rs:LL:CC
|
LL | write_bytes(dst, val, count)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow computing total size of `write_bytes`
LL | (&mut y as *mut i32).write_bytes(0u8, 1usize << (mem::size_of::<usize>() * 8 - 1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow computing total size of `write_bytes`
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: backtrace:
= note: inside `std::intrinsics::write_bytes::<i32>` at RUSTLIB/core/src/intrinsics.rs:LL:CC
= note: inside `std::ptr::mut_ptr::<impl *mut i32>::write_bytes` at RUSTLIB/core/src/ptr/mut_ptr.rs:LL:CC
note: inside `main` at $DIR/write_bytes_overflow.rs:LL:CC
--> $DIR/write_bytes_overflow.rs:LL:CC
|
LL | (&mut y as *mut i32).write_bytes(0u8, 1usize << (mem::size_of::<usize>() * 8 - 1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: inside `main` at $DIR/write_bytes_overflow.rs:LL:CC
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace