Skip to content

Commit 743c2d1

Browse files
authored
Merge pull request #5849 from tautschnig/fix-getenv
Pointer arithmetic check: do not use pointer-to-int conversion
2 parents 8ac57fd + 49481e2 commit 743c2d1

File tree

4 files changed

+11
-25
lines changed

4 files changed

+11
-25
lines changed

regression/cbmc-library/getenv-01/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
--signed-overflow-check --unsigned-overflow-check
3+
--signed-overflow-check --unsigned-overflow-check --pointer-overflow-check --pointer-check --bounds-check
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$

regression/cbmc/pointer-overflow1/test.desc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ main.c
33
--pointer-overflow-check --unsigned-overflow-check
44
^EXIT=10$
55
^SIGNAL=0$
6-
^\[main\.overflow\.\d+\] line 8 (pointer )?arithmetic overflow on .*: FAILURE
7-
^\[main\.overflow\.\d+\] line 9 (pointer )?arithmetic overflow on .*: FAILURE
6+
^\[main\.pointer_arithmetic\.\d+\] line 8 pointer arithmetic: pointer outside dynamic object bounds in .*: FAILURE
7+
^\[main\.pointer_arithmetic\.\d+\] line 9 pointer arithmetic: pointer outside dynamic object bounds in .*: FAILURE
88
^\[main\.overflow\.\d+\] line 10 (pointer )?arithmetic overflow on .*: FAILURE
9-
^\[main\.overflow\.\d+\] line 11 (pointer )?arithmetic overflow on .*: FAILURE
10-
^\[main\.overflow\.\d+\] line 12 (pointer )?arithmetic overflow on .*: FAILURE
9+
^\[main\.pointer_arithmetic\.\d+\] line 10 pointer arithmetic: pointer outside dynamic object bounds in .*: FAILURE
10+
^\[main\.pointer_arithmetic\.\d+\] line 11 pointer arithmetic: pointer outside dynamic object bounds in .*: FAILURE
11+
^\[main\.pointer_arithmetic\.\d+\] line 12 pointer arithmetic: pointer outside dynamic object bounds in .*: FAILURE
1112
^VERIFICATION FAILED$
1213
--
1314
^\[main\.overflow\.\d+\] line 1[45] (pointer )?arithmetic overflow on .*sizeof\(signed int\) .* : FAILURE
15+
^\[main\.overflow\.\d+\] line 1[45] pointer arithmetic: pointer outside dynamic object bounds in .*: FAILURE
1416
^warning: ignoring

regression/cbmc/pointer-overflow2/test.desc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ main.c
33
--pointer-overflow-check
44
^EXIT=0$
55
^SIGNAL=0$
6-
\[main.overflow.1\] line \d+ pointer arithmetic overflow on - in p - \(signed long (long )?int\)1: SUCCESS
7-
\[main.overflow.2\] line \d+ pointer arithmetic overflow on \+ in p \+ \(signed long (long )?int\)1: SUCCESS
8-
\[main.overflow.3\] line \d+ pointer arithmetic overflow on \+ in p \+ \(signed long (long )?int\)-1: SUCCESS
9-
\[main.overflow.4\] line \d+ pointer arithmetic overflow on - in p - \(signed long (long )?int\)-1: SUCCESS
6+
\[main.pointer_arithmetic.1\] line \d+ pointer arithmetic: invalid integer address in p - \(signed long (long )?int\)1: SUCCESS
7+
\[main.pointer_arithmetic.2\] line \d+ pointer arithmetic: invalid integer address in p \+ \(signed long (long )?int\)1: SUCCESS
8+
\[main.pointer_arithmetic.3\] line \d+ pointer arithmetic: invalid integer address in p \+ \(signed long (long )?int\)-1: SUCCESS
9+
\[main.pointer_arithmetic.4\] line \d+ pointer arithmetic: invalid integer address in p - \(signed long (long )?int\)-1: SUCCESS
1010
--
1111
^warning: ignoring

src/analyses/goto_check.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,22 +1181,6 @@ void goto_checkt::pointer_overflow_check(
11811181
expr.operands().size() == 2,
11821182
"pointer arithmetic expected to have exactly 2 operands");
11831183

1184-
// check for address space overflow by checking for overflow on integers
1185-
exprt overflow("overflow-" + expr.id_string(), bool_typet());
1186-
for(const auto &op : expr.operands())
1187-
{
1188-
overflow.add_to_operands(
1189-
typecast_exprt::conditional_cast(op, pointer_diff_type()));
1190-
}
1191-
1192-
add_guarded_property(
1193-
not_exprt(overflow),
1194-
"pointer arithmetic overflow on " + expr.id_string(),
1195-
"overflow",
1196-
expr.find_source_location(),
1197-
expr,
1198-
guard);
1199-
12001184
// the result must be within object bounds or one past the end
12011185
const auto size = from_integer(0, size_type());
12021186
auto conditions = get_pointer_dereferenceable_conditions(expr, size);

0 commit comments

Comments
 (0)