-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test to check that no pointer checks happen inside
kani::mem_init
- Loading branch information
1 parent
429c39f
commit c5ad7d4
Showing
4 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
tests/script-based-pre/mem-init-reinstrumentation/alloc-zeroed.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,22 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// kani-flags: -Z uninit-checks | ||
|
||
use std::alloc::{alloc_zeroed, Layout}; | ||
use std::slice::from_raw_parts; | ||
|
||
#[kani::proof] | ||
fn alloc_zeroed_to_slice() { | ||
let layout = Layout::from_size_align(32, 8).unwrap(); | ||
unsafe { | ||
// This returns initialized memory, so any further accesses are valid. | ||
let ptr = alloc_zeroed(layout); | ||
*ptr = 0x41; | ||
*ptr.add(1) = 0x42; | ||
*ptr.add(2) = 0x43; | ||
*ptr.add(3) = 0x44; | ||
*ptr.add(16) = 0x00; | ||
let _slice1 = from_raw_parts(ptr, 16); | ||
let _slice2 = from_raw_parts(ptr.add(16), 16); | ||
} | ||
} |
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,4 @@ | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
script: mem-init-reinstrumentation.sh | ||
expected: mem-init-reinstrumentation.expected |
1 change: 1 addition & 0 deletions
1
tests/script-based-pre/mem-init-reinstrumentation/mem-init-reinstrumentation.expected
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 @@ | ||
success: no pointer checks are detected in initialized memory instrumentaiton |
20 changes: 20 additions & 0 deletions
20
tests/script-based-pre/mem-init-reinstrumentation/mem-init-reinstrumentation.sh
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 @@ | ||
#!/usr/bin/env bash | ||
# Copyright Kani Contributors | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
set -u | ||
|
||
KANI_OUTPUT=`kani -Z uninit-checks alloc-zeroed.rs` | ||
echo "$KANI_OUTPUT" | egrep -q "kani::mem_init::.*pointer_dereference" | ||
INSTRUMENTATION_DETECTED=$? | ||
|
||
if [[ $INSTRUMENTATION_DETECTED == 0 ]]; then | ||
echo "failed: pointer checks are detected in initialized memory instrumentaiton" | ||
exit 1 | ||
elif [[ $INSTRUMENTATION_DETECTED == 1 ]]; then | ||
echo "success: no pointer checks are detected in initialized memory instrumentaiton" | ||
exit 0 | ||
else | ||
echo "failed: error occured when runnning egrep" | ||
exit 0 | ||
fi |