Skip to content

Commit 0b7fc3c

Browse files
committed
C++: Add a FP testcase involving flow through back-edges.
1 parent 48f2268 commit 0b7fc3c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-119/OverrunWriteProductFlow.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ edges
223223
| test.cpp:243:12:243:14 | str indirection [string] | test.cpp:243:16:243:21 | string indirection |
224224
| test.cpp:243:16:243:21 | string indirection | test.cpp:243:12:243:21 | string |
225225
| test.cpp:249:20:249:27 | call to my_alloc | test.cpp:250:12:250:12 | p |
226+
| test.cpp:256:17:256:22 | call to malloc | test.cpp:257:12:257:12 | p |
226227
nodes
227228
| test.cpp:16:11:16:21 | mk_string_t indirection [string] | semmle.label | mk_string_t indirection [string] |
228229
| test.cpp:18:5:18:30 | ... = ... | semmle.label | ... = ... |
@@ -405,6 +406,8 @@ nodes
405406
| test.cpp:243:16:243:21 | string indirection | semmle.label | string indirection |
406407
| test.cpp:249:20:249:27 | call to my_alloc | semmle.label | call to my_alloc |
407408
| test.cpp:250:12:250:12 | p | semmle.label | p |
409+
| test.cpp:256:17:256:22 | call to malloc | semmle.label | call to malloc |
410+
| test.cpp:257:12:257:12 | p | semmle.label | p |
408411
subpaths
409412
| test.cpp:242:22:242:27 | buffer | test.cpp:235:40:235:45 | buffer | test.cpp:236:12:236:17 | p_str indirection [post update] [string] | test.cpp:242:16:242:19 | set_string output argument [string] |
410413
#select
@@ -426,3 +429,4 @@ subpaths
426429
| test.cpp:232:3:232:8 | call to memset | test.cpp:228:43:228:48 | call to malloc | test.cpp:232:10:232:15 | buffer | This write may overflow $@ by 32 elements. | test.cpp:232:10:232:15 | buffer | buffer |
427430
| test.cpp:243:5:243:10 | call to memset | test.cpp:241:27:241:32 | call to malloc | test.cpp:243:12:243:21 | string | This write may overflow $@ by 1 element. | test.cpp:243:16:243:21 | string | string |
428431
| test.cpp:250:5:250:10 | call to memset | test.cpp:249:20:249:27 | call to my_alloc | test.cpp:250:12:250:12 | p | This write may overflow $@ by 1 element. | test.cpp:250:12:250:12 | p | p |
432+
| test.cpp:257:5:257:10 | call to memset | test.cpp:256:17:256:22 | call to malloc | test.cpp:257:12:257:12 | p | This write may overflow $@ by 32 elements. | test.cpp:257:12:257:12 | p | p |

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-119/test.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,12 @@ void* my_alloc(unsigned size);
248248
void foo(unsigned size) {
249249
int* p = (int*)my_alloc(size); // BAD
250250
memset(p, 0, size + 1);
251+
}
252+
253+
void test6(unsigned long n, char *p) {
254+
while (unknown()) {
255+
n++;
256+
p = (char *)malloc(n);
257+
memset(p, 0, n); // GOOD [FALSE POSITIVE]
258+
}
251259
}

0 commit comments

Comments
 (0)