Skip to content

Commit

Permalink
Merge pull request #1949 from GaloisInc/rem/iss-1932
Browse files Browse the repository at this point in the history
iss-1932
  • Loading branch information
mergify[bot] authored Sep 28, 2023
2 parents cd6fa80 + 29f9c9e commit 1fd52b9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 2 deletions.
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 -frecord-command-line -o $@ $<
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 "array type index out of bounds"; then
exit 0
else
exit 1
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

0 comments on commit 1fd52b9

Please sign in to comment.