Skip to content

Commit

Permalink
rustup
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Aug 31, 2022
1 parent 7c40e0a commit 4383da8
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 26 deletions.
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
94b2b15e63c5d2b2a6a0910e3dae554ce9415bf9
4fd4de7ea358ad6fc28c5780533ea8ccc09e1006
1 change: 1 addition & 0 deletions tests/fail/invalid_int.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(invalid_value)]
// Validation makes this fail in the wrong place
// Make sure we find these even with many checks disabled.
//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
Expand Down
4 changes: 2 additions & 2 deletions tests/fail/validity/invalid_bool_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

union MyUninit {
init: (),
uninit: bool,
uninit: [bool; 1],
}

fn main() {
let _b = unsafe { MyUninit { init: () }.uninit }; //~ ERROR: uninitialized
let _b = unsafe { MyUninit { init: () }.uninit }; //~ ERROR: constructing invalid value
}
4 changes: 2 additions & 2 deletions tests/fail/validity/invalid_bool_uninit.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
error: Undefined Behavior: constructing invalid value at [0]: encountered uninitialized memory, but expected a boolean
--> $DIR/invalid_bool_uninit.rs:LL:CC
|
LL | let _b = unsafe { MyUninit { init: () }.uninit };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [0]: encountered uninitialized memory, but expected a boolean
|
= 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
Expand Down
4 changes: 2 additions & 2 deletions tests/fail/validity/invalid_char_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

union MyUninit {
init: (),
uninit: char,
uninit: [char; 1],
}

fn main() {
let _b = unsafe { MyUninit { init: () }.uninit }; //~ ERROR: uninitialized
let _b = unsafe { MyUninit { init: () }.uninit }; //~ ERROR: constructing invalid value
}
4 changes: 2 additions & 2 deletions tests/fail/validity/invalid_char_uninit.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
error: Undefined Behavior: constructing invalid value at [0]: encountered uninitialized memory, but expected a unicode scalar value
--> $DIR/invalid_char_uninit.rs:LL:CC
|
LL | let _b = unsafe { MyUninit { init: () }.uninit };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [0]: encountered uninitialized memory, but expected a unicode scalar value
|
= 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
Expand Down
4 changes: 2 additions & 2 deletions tests/fail/validity/invalid_fnptr_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

union MyUninit {
init: (),
uninit: fn(),
uninit: [fn(); 1],
}

fn main() {
let _b = unsafe { MyUninit { init: () }.uninit }; //~ ERROR: uninitialized
let _b = unsafe { MyUninit { init: () }.uninit }; //~ ERROR: constructing invalid value
}
4 changes: 2 additions & 2 deletions tests/fail/validity/invalid_fnptr_uninit.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
error: Undefined Behavior: constructing invalid value at [0]: encountered uninitialized memory, but expected a function pointer
--> $DIR/invalid_fnptr_uninit.rs:LL:CC
|
LL | let _b = unsafe { MyUninit { init: () }.uninit };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at [0]: encountered uninitialized memory, but expected a function pointer
|
= 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
Expand Down
5 changes: 3 additions & 2 deletions tests/fail/validity/uninit_float.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#![allow(deprecated)]
#![allow(deprecated, invalid_value)]
// This test is adapted from https://github.com/rust-lang/miri/issues/1340#issue-600900312.

fn main() {
// Deliberately using `mem::uninitialized` to make sure that despite all the mitigations, we consider this UB.
let _val: f32 = unsafe { std::mem::uninitialized() };
// The array avoids a `Scalar` layout which detects uninit without even doing validation.
let _val: [f32; 1] = unsafe { std::mem::uninitialized() };
//~^ ERROR: uninitialized
}
6 changes: 3 additions & 3 deletions tests/fail/validity/uninit_float.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
error: Undefined Behavior: constructing invalid value at .value[0]: encountered uninitialized bytes
--> $DIR/uninit_float.rs:LL:CC
|
LL | let _val: f32 = unsafe { std::mem::uninitialized() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
LL | let _val: [f32; 1] = unsafe { std::mem::uninitialized() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .value[0]: encountered uninitialized 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
Expand Down
4 changes: 3 additions & 1 deletion tests/fail/validity/uninit_integer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![allow(invalid_value)]
// This test is from https://github.com/rust-lang/miri/issues/1340#issue-600900312.

fn main() {
let _val = unsafe { std::mem::MaybeUninit::<usize>::uninit().assume_init() };
// The array avoids a `Scalar` layout which detects uninit without even doing validation.
let _val = unsafe { std::mem::MaybeUninit::<[usize; 1]>::uninit().assume_init() };
//~^ ERROR: uninitialized
}
6 changes: 3 additions & 3 deletions tests/fail/validity/uninit_integer.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
error: Undefined Behavior: constructing invalid value at .value[0]: encountered uninitialized bytes
--> $DIR/uninit_integer.rs:LL:CC
|
LL | let _val = unsafe { std::mem::MaybeUninit::<usize>::uninit().assume_init() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
LL | let _val = unsafe { std::mem::MaybeUninit::<[usize; 1]>::uninit().assume_init() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .value[0]: encountered uninitialized 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
Expand Down
5 changes: 4 additions & 1 deletion tests/fail/validity/uninit_raw_ptr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#![allow(invalid_value)]

fn main() {
let _val = unsafe { std::mem::MaybeUninit::<*const u8>::uninit().assume_init() };
// The array avoids a `Scalar` layout which detects uninit without even doing validation.
let _val = unsafe { std::mem::MaybeUninit::<[*const u8; 1]>::uninit().assume_init() };
//~^ ERROR: uninitialized
}
6 changes: 3 additions & 3 deletions tests/fail/validity/uninit_raw_ptr.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
error: Undefined Behavior: constructing invalid value at .value[0]: encountered uninitialized memory, but expected a raw pointer
--> $DIR/uninit_raw_ptr.rs:LL:CC
|
LL | let _val = unsafe { std::mem::MaybeUninit::<*const u8>::uninit().assume_init() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
LL | let _val = unsafe { std::mem::MaybeUninit::<[*const u8; 1]>::uninit().assume_init() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .value[0]: encountered uninitialized memory, but expected a raw pointer
|
= 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
Expand Down

0 comments on commit 4383da8

Please sign in to comment.