Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable concrete playback for failure of UB checks #2727

Merged
merged 2 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kani-driver/src/concrete_playback/test_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ mod concrete_vals_extractor {
result_items
.iter()
.filter(|prop| {
(prop.property_class() == "assertion" && prop.status == CheckStatus::Failure)
(prop.property_class() != "unwind" && prop.status == CheckStatus::Failure)
|| (prop.property_class() == "cover" && prop.status == CheckStatus::Satisfied)
})
.map(|property| {
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/concrete-playback/ub/null_ptr/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
VERIFICATION:- FAILED

Concrete playback
```
#[test]
fn kani_concrete_playback_null_ptr
let concrete_vals: Vec<Vec<u8>> = vec![
// 15
vec![15, 0, 0, 0],
];
kani::concrete_playback_run(concrete_vals, null_ptr);
}
```
15 changes: 15 additions & 0 deletions tests/ui/concrete-playback/ub/null_ptr/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

// kani-flags: -Zconcrete-playback --concrete-playback=print

// This test checks that Kani generates a concrete playback test for UB checks
// (e.g. dereferencing a null pointer)

#[kani::proof]
fn null_ptr() {
let x = 42;
let nd: i32 = kani::any();
let ptr: *const i32 = if nd != 15 { &x as *const i32 } else { std::ptr::null() };
let _y = unsafe { *ptr };
}
13 changes: 13 additions & 0 deletions tests/ui/concrete-playback/ub/oob_ptr/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
VERIFICATION:- FAILED

Concrete playback
```
#[test]
fn kani_concrete_playback_oob_ptr
let concrete_vals: Vec<Vec<u8>> = vec![
// 3ul
vec![3, 0, 0, 0, 0, 0, 0, 0],
];
kani::concrete_playback_run(concrete_vals, oob_ptr);
}
```
15 changes: 15 additions & 0 deletions tests/ui/concrete-playback/ub/oob_ptr/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

// kani-flags: -Zconcrete-playback --concrete-playback=print

// This test checks that Kani generates a concrete playback test for UB checks
// (e.g. dereferencing a pointer that is outside the object bounds)

#[kani::proof]
fn oob_ptr() {
let v = vec![1, 2, 3];
// BUG: predicate should use strict less-than, i.e. `*idx < v.len()`
let idx: usize = kani::any_where(|idx| *idx <= v.len());
let _x = unsafe { *v.get_unchecked(idx) };
}