Skip to content

Commit d7aefd4

Browse files
author
Daniel Kroening
committed
Merge pull request #106 from cristina-david/java_pointer_check
Java pointer checks
2 parents 2675a17 + 6987879 commit d7aefd4

File tree

10 files changed

+73
-16
lines changed

10 files changed

+73
-16
lines changed
223 Bytes
Binary file not shown.
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class B {
2+
int j;
3+
}
4+
5+
class A {
6+
int i;
7+
B b;
8+
}
9+
10+
public class missing_class1 {
11+
public static void main(String[] args) {
12+
A a = new A();
13+
B b = a.b;
14+
int j = b.j; // NULL pointer dereference
15+
}
16+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
missing_class1.class
3+
--pointer-check
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
^warning: ignoring
207 Bytes
Binary file not shown.
277 Bytes
Binary file not shown.
Binary file not shown.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class A {
2+
int val;
3+
}
4+
5+
class B {
6+
int getVal(A a) {
7+
return a.val;
8+
}
9+
}
10+
11+
class pointer_check1 {
12+
public static void main(String[] args) {
13+
B b = new B();
14+
int myval = b.getVal(null);
15+
}
16+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
pointer_check1.class
3+
--pointer-check
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
--
8+
^warning: ignoring

src/analyses/goto_check.cpp

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -944,23 +944,32 @@ void goto_checkt::pointer_validity_check(
944944
expr,
945945
guard);
946946

947-
if(flags.is_unknown() || flags.is_dynamic_heap())
948-
add_guarded_claim(
949-
not_exprt(deallocated(pointer, ns)),
950-
"dereference failure: deallocated dynamic object",
951-
"pointer dereference",
952-
expr.find_source_location(),
953-
expr,
954-
guard);
947+
symbol_tablet symbol_table = ns.get_symbol_table();
955948

956-
if(flags.is_unknown() || flags.is_dynamic_local())
957-
add_guarded_claim(
958-
not_exprt(dead_object(pointer, ns)),
959-
"dereference failure: dead object",
960-
"pointer dereference",
961-
expr.find_source_location(),
962-
expr,
963-
guard);
949+
symbol_tablet::symbolst::iterator s_it =
950+
symbol_table.symbols.find(CPROVER_PREFIX "initialize");
951+
952+
// For Java don't check dereference of a deallocated or dead object
953+
if (s_it == symbol_table.symbols.end() || (s_it->second).mode != ID_java)
954+
{
955+
if(flags.is_unknown() || flags.is_dynamic_heap())
956+
add_guarded_claim(
957+
not_exprt(deallocated(pointer, ns)),
958+
"dereference failure: deallocated dynamic object",
959+
"pointer dereference",
960+
expr.find_source_location(),
961+
expr,
962+
guard);
963+
964+
if(flags.is_unknown() || flags.is_dynamic_local())
965+
add_guarded_claim(
966+
not_exprt(dead_object(pointer, ns)),
967+
"dereference failure: dead object",
968+
"pointer dereference",
969+
expr.find_source_location(),
970+
expr,
971+
guard);
972+
}
964973

965974
if(enable_bounds_check)
966975
{

0 commit comments

Comments
 (0)