-
Notifications
You must be signed in to change notification settings - Fork 97
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
1 parent
b8369e5
commit 49253b3
Showing
8 changed files
with
132 additions
and
9 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
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FAILURE\ | ||
memset destination region writeable |
19 changes: 19 additions & 0 deletions
19
tests/expected/intrinsics/write_bytes/out-of-bounds/main.rs
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// Checks that `write_bytes` fails if an out-of-bounds write is made. | ||
|
||
// This test is a modified version of the example in | ||
// https://doc.rust-lang.org/std/ptr/fn.write_bytes.html | ||
#![feature(core_intrinsics)] | ||
use std::intrinsics::write_bytes; | ||
|
||
#[kani::proof] | ||
fn main() { | ||
let mut vec = vec![0u32; 4]; | ||
unsafe { | ||
let vec_ptr = vec.as_mut_ptr().add(4); | ||
write_bytes(vec_ptr, 0xfe, 1); | ||
} | ||
assert_eq!(vec, [0, 0, 0, 0]); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FAILURE\ | ||
write_bytes: attempt to compute `bytes` which would overflow |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// Checks that `write_bytes` triggers the overflow check. | ||
|
||
// This test is a modified version of the example in | ||
// https://doc.rust-lang.org/std/ptr/fn.write_bytes.html | ||
#![feature(core_intrinsics)] | ||
use std::intrinsics::write_bytes; | ||
|
||
#[kani::proof] | ||
fn main() { | ||
let mut vec = vec![0u32; 4]; | ||
unsafe { | ||
let vec_ptr = vec.as_mut_ptr(); | ||
// Passing `usize::MAX + 1` is guaranteed to | ||
// overflow when computing the number of bytes | ||
write_bytes(vec_ptr, 0xfe, usize::MAX / 4 + 1); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FAILURE\ | ||
`dst` is properly aligned |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// Checks that `write_bytes` fails when `dst` is not aligned. | ||
|
||
// This test is a modified version of the example in | ||
// https://doc.rust-lang.org/std/ptr/fn.write_bytes.html | ||
use std::intrinsics::write_bytes; | ||
|
||
#[kani::proof] | ||
fn main() { | ||
let mut vec = vec![0u32; 4]; | ||
unsafe { | ||
let vec_ptr = vec.as_mut_ptr(); | ||
// Obtain an unaligned pointer by casting into `*mut u8`, | ||
// adding an offset of 1 and casting back into `*mut u32` | ||
let vec_ptr_u8: *mut u8 = vec_ptr as *mut u8; | ||
let unaligned_ptr = vec_ptr_u8.add(1) as *mut u32; | ||
write_bytes(unaligned_ptr, 0xfe, 2); | ||
} | ||
assert_eq!(vec, [0xfefefe00, 0xfefefefe, 0x000000fe, 0]); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// Checks that `write_bytes` works as expected. | ||
|
||
// This test is a modified version of the example in | ||
// https://doc.rust-lang.org/std/ptr/fn.write_bytes.html | ||
#![feature(core_intrinsics)] | ||
use std::intrinsics::write_bytes; | ||
|
||
#[kani::proof] | ||
fn main() { | ||
let mut vec = vec![0u32; 4]; | ||
unsafe { | ||
let vec_ptr = vec.as_mut_ptr(); | ||
write_bytes(vec_ptr, 0xfe, 2); | ||
} | ||
assert_eq!(vec, [0xfefefefe, 0xfefefefe, 0, 0]); | ||
} |