Skip to content

Commit 779d0aa

Browse files
author
Daniel Kroening
authored
Merge pull request #1574 from diffblue/taint-memcpy-develop
transfer taint with memcpy
2 parents 28a4846 + fa7d62a commit 779d0aa

File tree

6 files changed

+58
-0
lines changed

6 files changed

+58
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
default: tests.log
2+
3+
test:
4+
@../test.pl -p -c ../../../src/goto-analyzer/goto-analyzer
5+
6+
tests.log: ../test.pl
7+
@../test.pl -p -c ../../../src/goto-analyzer/goto-analyzer
8+
9+
show:
10+
@for dir in *; do \
11+
if [ -d "$$dir" ]; then \
12+
vim -o "$$dir/*.java" "$$dir/*.out"; \
13+
fi; \
14+
done;
15+
16+
clean:
17+
find -name '*.out' -execdir $(RM) '{}' \;
18+
find -name '*.gb' -execdir $(RM) '{}' \;
19+
$(RM) tests.log
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <string.h>
2+
3+
void my_f(void *) { }
4+
void my_h(void *) { }
5+
6+
void my_function()
7+
{
8+
void *o1;
9+
my_f(o1); // T1 source
10+
11+
void *o2;
12+
memcpy(o2, o1, 100);
13+
14+
my_h(o2); // T1 sink
15+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[
2+
{ "id": "my_f", "kind": "source", "where": "parameter1", "taint": "T1", "function": "my_f" },
3+
{ "id": "my_h", "kind": "sink", "where": "parameter1", "taint": "T1", "function": "my_h", "message": "There is a T1 flow" }
4+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
main.o
3+
--taint taint.json
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^file main.c line 12( function .*)?: There is a T1 flow \(taint rule my_h\)$
7+
--

src/analyses/custom_bitvector_analysis.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,19 @@ void custom_bitvector_domaint::transform(
380380
}
381381
}
382382
}
383+
else if(identifier=="memcpy" ||
384+
identifier=="memmove")
385+
{
386+
if(code_function_call.arguments().size()==3)
387+
{
388+
// we copy all tracked bits from op1 to op0
389+
// we do not consider any bits attached to the size op2
390+
dereference_exprt lhs_deref(code_function_call.arguments()[0]);
391+
dereference_exprt rhs_deref(code_function_call.arguments()[1]);
392+
393+
assign_struct_rec(from, lhs_deref, rhs_deref, cba, ns);
394+
}
395+
}
383396
else
384397
{
385398
goto_programt::const_targett next=from;

0 commit comments

Comments
 (0)