Skip to content

Commit 6dfe0a0

Browse files
authored
Add a multi-crate test for rust-lang#3061 (rust-lang#3076)
This is a follow-up on rust-lang#3063 that adds a test with multiple crates to make sure this scenario is correctly handled and that Kani reports the bug. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent fb6300d commit 6dfe0a0

File tree

6 files changed

+48
-0
lines changed

6 files changed

+48
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright Kani Contributors
2+
# SPDX-License-Identifier: Apache-2.0 OR MIT
3+
[workspace]
4+
members = ["crate-with-bug", "crate-with-harness"]
5+
resolver = "2"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright Kani Contributors
2+
# SPDX-License-Identifier: Apache-2.0 OR MIT
3+
[package]
4+
name = "crate-with-bug"
5+
version = "0.1.0"
6+
edition = "2021"
7+
8+
[dependencies]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright Kani Contributors
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
// This function contains a use-after-free bug.
5+
6+
pub fn fn_with_bug() -> i32 {
7+
let raw_ptr = {
8+
let var = 10;
9+
&var as *const i32
10+
};
11+
unsafe { *raw_ptr }
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright Kani Contributors
2+
# SPDX-License-Identifier: Apache-2.0 OR MIT
3+
[package]
4+
name = "crate-with-harness"
5+
version = "0.1.0"
6+
edition = "2021"
7+
8+
[dependencies]
9+
crate-with-bug = { path = "../crate-with-bug" }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Status: FAILURE\
2+
Description: "dereference failure: dead object"\
3+
in function crate_with_bug::fn_with_bug
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright Kani Contributors
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
// This test checks that Kani captures the case of a use-after-free issue as
5+
// described in https://github.com/model-checking/kani/issues/3061 even across
6+
// crates. The test calls a function from another crate that has the bug.
7+
8+
#[kani::proof]
9+
pub fn call_fn_with_bug() {
10+
let _x = crate_with_bug::fn_with_bug();
11+
}

0 commit comments

Comments
 (0)