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

iss-1932 #1949

Merged
merged 3 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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: 2 additions & 0 deletions intTests/test_llvm_bound_check/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bound.bc : bound.c
clang -c -emit-llvm -o bound.bc bound.c
mccleeary-galois marked this conversation as resolved.
Show resolved Hide resolved
Binary file added intTests/test_llvm_bound_check/bound.bc
Binary file not shown.
5 changes: 5 additions & 0 deletions intTests/test_llvm_bound_check/bound.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stdint.h>

uint32_t f(uint32_t x[2]) {
return x[1];
}
15 changes: 15 additions & 0 deletions intTests/test_llvm_bound_check/bound.saw
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
let f_spec = do {
x <- llvm_alloc (llvm_array 2 (llvm_int 32));
a <- llvm_fresh_var "a" (llvm_int 32);
llvm_points_to (llvm_elem x 1) (llvm_term a);

// BAD: Out-of-bounds write
llvm_points_to (llvm_elem x 2) (llvm_term a);

llvm_execute_func [x];

llvm_return (llvm_term a);
};

m <- llvm_load_module "bound.bc";
llvm_verify m "f" [] false f_spec z3;
10 changes: 10 additions & 0 deletions intTests/test_llvm_bound_check/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

set -e

# We want to ensure there isn't a memory store failure and this is caught during type checking of Setup Value
if $SAW bound.saw | grep -q "Memory store failed"; then
mccleeary-galois marked this conversation as resolved.
Show resolved Hide resolved
exit 1
else
exit 0
fi
4 changes: 2 additions & 2 deletions src/SAWScript/Crucible/LLVM/ResolveSetupValue.hs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ typeOfSetupValue cc env nameEnv val =
Right memTy' ->
case memTy' of
Crucible.ArrayType n memTy''
| fromIntegral i <= n -> return (Crucible.PtrType (Crucible.MemType memTy''))
| fromIntegral i < n -> return (Crucible.PtrType (Crucible.MemType memTy''))
| otherwise -> throwError $ unwords $
[ "typeOfSetupValue: array type index out of bounds"
, "(index: " ++ show i ++ ")"
Expand Down Expand Up @@ -574,7 +574,7 @@ resolveSetupElemOffset cc env nameEnv v i = do
Right memTy' ->
case memTy' of
Crucible.ArrayType n memTy''
| fromIntegral i <= n -> return (fromIntegral i * Crucible.memTypeSize dl memTy'')
| fromIntegral i < n -> return (fromIntegral i * Crucible.memTypeSize dl memTy'')
Crucible.StructType si ->
case Crucible.siFieldOffset si i of
Just d -> return d
Expand Down