-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
102 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
//@error-pattern: overflow computing total size | ||
use std::mem; | ||
|
||
fn main() { | ||
let x = 0; | ||
let mut y = 0; | ||
unsafe { | ||
(&mut y as *mut i32).copy_from(&x, 1usize << (mem::size_of::<usize>() * 8 - 1)); | ||
//~^ERROR: overflow computing total size | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
//@error-pattern: pointer to 5 bytes starting at offset 0 is out-of-bounds | ||
fn main() { | ||
let v = [0i8; 4]; | ||
let x = &v as *const i8; | ||
// The error is inside another function, so we cannot match it by line | ||
let x = unsafe { x.offset(5) }; | ||
let x = unsafe { x.offset(5) }; //~ERROR: pointer to 5 bytes starting at offset 0 is out-of-bounds | ||
panic!("this should never print: {:?}", x); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
//@error-pattern: overflowing in-bounds pointer arithmetic | ||
fn main() { | ||
let v = [0i8; 4]; | ||
let x = &v as *const i8; | ||
let x = unsafe { x.offset(isize::MIN) }; | ||
let x = unsafe { x.offset(isize::MIN) }; //~ERROR: overflowing in-bounds pointer arithmetic | ||
panic!("this should never print: {:?}", x); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
//@error-pattern: pointer to 1 byte starting at offset -1 is out-of-bounds | ||
fn main() { | ||
let v = [0i8; 4]; | ||
let x = &v as *const i8; | ||
let x = unsafe { x.offset(-1) }; | ||
let x = unsafe { x.offset(-1) }; //~ERROR: pointer to 1 byte starting at offset -1 is out-of-bounds | ||
panic!("this should never print: {:?}", x); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
#![feature(core_intrinsics)] | ||
|
||
use std::intrinsics::*; | ||
#![feature(unchecked_math)] | ||
|
||
fn main() { | ||
unsafe { | ||
let _n = unchecked_shr(1i64, 64); | ||
let _n = 1i64.unchecked_shr(64); | ||
//~^ ERROR: overflowing shift by 64 in `unchecked_shr` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
//@error-pattern: null pointer is a dangling pointer | ||
//@compile-flags: -Zmiri-permissive-provenance | ||
|
||
#[rustfmt::skip] // fails with "left behind trailing whitespace" | ||
fn main() { | ||
let x = 0 as *mut i32; | ||
let _x = x.wrapping_offset(8); // ok, this has no inbounds tag | ||
let _x = unsafe { x.offset(0) }; // UB despite offset 0, NULL is never inbounds | ||
//~^ERROR: null pointer is a dangling pointer | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
#![feature(core_intrinsics)] | ||
|
||
use std::intrinsics::ptr_offset_from; | ||
|
||
fn main() { | ||
let start_ptr = &4 as *const _ as *const u8; | ||
let length = 10; | ||
let end_ptr = start_ptr.wrapping_add(length); | ||
// Even if the offset is 0, a dangling OOB pointer is not allowed. | ||
unsafe { ptr_offset_from(end_ptr, end_ptr) }; //~ERROR: pointer at offset 10 is out-of-bounds | ||
unsafe { end_ptr.offset_from(end_ptr) }; //~ERROR: pointer at offset 10 is out-of-bounds | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
//@error-pattern: is a dangling pointer | ||
//@compile-flags: -Zmiri-permissive-provenance | ||
|
||
fn main() { | ||
// Can't offset an integer pointer by non-zero offset. | ||
unsafe { | ||
let _val = (1 as *mut u8).offset(1); | ||
let _val = (1 as *mut u8).offset(1); //~ERROR: is a dangling pointer | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
//@error-pattern: is a dangling pointer | ||
//@compile-flags: -Zmiri-permissive-provenance | ||
|
||
fn main() { | ||
let ptr = Box::into_raw(Box::new(0u32)); | ||
// Can't start with an integer pointer and get to something usable | ||
unsafe { | ||
let _val = (1 as *mut u8).offset(ptr as isize); | ||
let _val = (1 as *mut u8).offset(ptr as isize); //~ERROR: is a dangling pointer | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
//@error-pattern: overflowing in-bounds pointer arithmetic | ||
fn main() { | ||
let v = [1i8, 2]; | ||
let x = &v[1] as *const i8; | ||
let _val = unsafe { x.offset(isize::MIN) }; | ||
let _val = unsafe { x.offset(isize::MIN) }; //~ERROR: overflowing in-bounds pointer arithmetic | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
//@error-pattern: pointer at offset 32 is out-of-bounds | ||
|
||
#[rustfmt::skip] // fails with "left behind trailing whitespace" | ||
fn main() { | ||
let x = Box::into_raw(Box::new(0u32)); | ||
let x = x.wrapping_offset(8); // ok, this has no inbounds tag | ||
let _x = unsafe { x.offset(0) }; // UB despite offset 0, the pointer is not inbounds of the only object it can point to | ||
//~^ERROR: pointer at offset 32 is out-of-bounds | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
#![feature(core_intrinsics)] | ||
#![feature(unchecked_math)] | ||
|
||
fn main() { | ||
// MAX overflow | ||
unsafe { | ||
std::intrinsics::unchecked_add(40000u16, 30000); //~ ERROR: overflow executing `unchecked_add` | ||
} | ||
let _val = unsafe { 40000u16.unchecked_add(30000) }; //~ ERROR: overflow executing `unchecked_add` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
#![feature(core_intrinsics)] | ||
#![feature(unchecked_math)] | ||
|
||
fn main() { | ||
// MIN overflow | ||
unsafe { | ||
std::intrinsics::unchecked_add(-30000i16, -8000); //~ ERROR: overflow executing `unchecked_add` | ||
} | ||
let _val = unsafe { (-30000i16).unchecked_add(-8000) }; //~ ERROR: overflow executing `unchecked_add` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.