Skip to content

Commit 39294c6

Browse files
committed
Add cmp_buff_overflow as test
1 parent 79d941a commit 39294c6

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

flake.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@
7070
buildPhase = ''
7171
mkdir $out
7272
make -C ./test_programs
73-
for test in "./tests/*"; do
73+
for test in ./tests/*; do
7474
python $test
7575
done
76-
cp *.json $out
76+
cp *.json $out/
7777
'';
7878
};
7979

tests/cmp_buff_overflow.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import claripy
2+
import cozy.analysis as analysis
3+
import cozy.claripy_ext as claripy_ext
4+
from cozy.directive import Assume
5+
from cozy.project import Project
6+
from cozy.constants import *
7+
import cozy.primitives as primitives
8+
import cozy.execution_graph as execution_graph
9+
10+
arg0 = [5, 4, 3]
11+
arg1 = claripy.BVS('idx_arg', INT_SIZE * 8)
12+
13+
def construct_args(sess):
14+
# Constrain the first argument to satisfy -10 <= arg1 <= 10
15+
sess.add_constraints(arg1.SGE(-10))
16+
sess.add_constraints(arg1.SLE(10))
17+
return [arg0, arg1]
18+
19+
proj_pre = Project('test_programs/buff_overflow/buff_overflow')
20+
# The patched function is the same as the original, except it has an if statement
21+
# to check if the input argument is NULL
22+
proj_post = Project('test_programs/buff_overflow/buff_overflow_patched')
23+
24+
proj_pre.add_prototype('patch_fun', 'int patch_fun(int a[], int i)')
25+
proj_post.add_prototype('patch_fun', 'int patch_fun(int a[], int i)')
26+
27+
sess_pre = proj_pre.session('patch_fun')
28+
sess_post = proj_post.session('patch_fun')
29+
30+
rslt_pre = sess_pre.run(construct_args(sess_pre))
31+
rslt_post = sess_post.run(construct_args(sess_post))
32+
33+
def concrete_post_processor(args):
34+
return (args[0], primitives.from_twos_comp(args[1].concrete_value, 32))
35+
36+
args = (arg0, arg1)
37+
38+
comparison = analysis.Comparison(rslt_pre, rslt_post)
39+
40+
execution_graph.dump_comparison(proj_pre, proj_post, rslt_pre, rslt_post, comparison, output_file="cmp_buff_overflow.json", args=args, num_examples=2, include_actions=True)

0 commit comments

Comments
 (0)