Skip to content

Commit

Permalink
Enable concrete playback for failure of UB checks (model-checking#2727)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhassan-aws committed Sep 2, 2023
1 parent 7831ad0 commit f23126a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
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) };
}

0 comments on commit f23126a

Please sign in to comment.