Skip to content

Commit ed0524d

Browse files
authored
Merge pull request github#13155 from jketema/invalid-pointer-deref-fp
C++: Add FP test case for `cpp/invalid-pointer-deref`
2 parents ef65931 + eb493a1 commit ed0524d

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-193/pointer-deref/InvalidPointerDeref.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,10 @@ edges
649649
| test.cpp:280:13:280:24 | new[] | test.cpp:281:14:281:15 | xs |
650650
| test.cpp:290:13:290:24 | new[] | test.cpp:291:14:291:15 | xs |
651651
| test.cpp:290:13:290:24 | new[] | test.cpp:292:30:292:30 | x |
652+
| test.cpp:304:15:304:26 | new[] | test.cpp:307:5:307:6 | xs |
653+
| test.cpp:304:15:304:26 | new[] | test.cpp:308:5:308:6 | xs |
654+
| test.cpp:308:5:308:6 | xs | test.cpp:308:5:308:11 | access to array |
655+
| test.cpp:308:5:308:11 | access to array | test.cpp:308:5:308:29 | Store: ... = ... |
652656
#select
653657
| test.cpp:6:14:6:15 | Load: * ... | test.cpp:4:15:4:20 | call to malloc | test.cpp:6:14:6:15 | Load: * ... | This read might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:4:15:4:20 | call to malloc | call to malloc | test.cpp:5:19:5:22 | size | size |
654658
| test.cpp:8:14:8:21 | Load: * ... | test.cpp:4:15:4:20 | call to malloc | test.cpp:8:14:8:21 | Load: * ... | This read might be out of bounds, as the pointer might be equal to $@ + $@ + 1. | test.cpp:4:15:4:20 | call to malloc | call to malloc | test.cpp:5:19:5:22 | size | size |
@@ -672,3 +676,4 @@ edges
672676
| test.cpp:254:9:254:16 | Store: ... = ... | test.cpp:248:24:248:30 | call to realloc | test.cpp:254:9:254:16 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:248:24:248:30 | call to realloc | call to realloc | test.cpp:254:11:254:11 | i | i |
673677
| test.cpp:264:13:264:14 | Load: * ... | test.cpp:260:13:260:24 | new[] | test.cpp:264:13:264:14 | Load: * ... | This read might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:260:13:260:24 | new[] | new[] | test.cpp:261:19:261:21 | len | len |
674678
| test.cpp:274:5:274:10 | Store: ... = ... | test.cpp:270:13:270:24 | new[] | test.cpp:274:5:274:10 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:270:13:270:24 | new[] | new[] | test.cpp:271:19:271:21 | len | len |
679+
| test.cpp:308:5:308:29 | Store: ... = ... | test.cpp:304:15:304:26 | new[] | test.cpp:308:5:308:29 | Store: ... = ... | This write might be out of bounds, as the pointer might be equal to $@ + $@. | test.cpp:304:15:304:26 | new[] | new[] | test.cpp:308:8:308:10 | ... + ... | ... + ... |

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-193/pointer-deref/test.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,18 @@ void test20(unsigned len)
293293
{
294294
*x = 0; // GOOD
295295
}
296-
}
296+
}
297+
298+
void* test21_get(int n);
299+
300+
void test21() {
301+
int n = 0;
302+
while (test21_get(n)) n+=2;
303+
304+
void** xs = new void*[n];
305+
306+
for (int i = 0; i < n; i += 2) {
307+
xs[i] = test21_get(i);
308+
xs[i+1] = test21_get(i+1);
309+
}
310+
}

cpp/ql/test/library-tests/ir/range-analysis/test.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,13 @@
4949
return 0;
5050
}
5151

52+
void* f3_get(int n);
53+
54+
void f3() {
55+
int n = 0;
56+
while (f3_get(n)) n+=2;
57+
58+
for (int i = 0; i < n; i += 2) {
59+
range(i); // $ range=>=0 SPURIOUS: range="<=call to f3_get-1" range="<=call to f3_get-2"
60+
}
61+
}

0 commit comments

Comments
 (0)