Skip to content

Commit 635d290

Browse files
committed
C++: Add testcase with FP.
1 parent 67afbee commit 635d290

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ edges
209209
| test.cpp:207:17:207:19 | str indirection [string] | test.cpp:207:22:207:27 | string |
210210
| test.cpp:207:17:207:19 | str indirection [string] | test.cpp:207:22:207:27 | string indirection |
211211
| test.cpp:207:22:207:27 | string indirection | test.cpp:207:22:207:27 | string |
212+
| test.cpp:214:24:214:24 | p | test.cpp:216:10:216:10 | p |
213+
| test.cpp:220:43:220:48 | call to malloc | test.cpp:222:15:222:20 | buffer |
214+
| test.cpp:222:15:222:20 | buffer | test.cpp:214:24:214:24 | p |
212215
nodes
213216
| test.cpp:16:11:16:21 | mk_string_t indirection [string] | semmle.label | mk_string_t indirection [string] |
214217
| test.cpp:18:5:18:30 | ... = ... | semmle.label | ... = ... |
@@ -374,6 +377,10 @@ nodes
374377
| test.cpp:207:17:207:19 | str indirection [string] | semmle.label | str indirection [string] |
375378
| test.cpp:207:22:207:27 | string | semmle.label | string |
376379
| test.cpp:207:22:207:27 | string indirection | semmle.label | string indirection |
380+
| test.cpp:214:24:214:24 | p | semmle.label | p |
381+
| test.cpp:216:10:216:10 | p | semmle.label | p |
382+
| test.cpp:220:43:220:48 | call to malloc | semmle.label | call to malloc |
383+
| test.cpp:222:15:222:20 | buffer | semmle.label | buffer |
377384
subpaths
378385
#select
379386
| test.cpp:42:5:42:11 | call to strncpy | test.cpp:18:19:18:24 | call to malloc | test.cpp:42:18:42:23 | string | This write may overflow $@ by 1 element. | test.cpp:42:18:42:23 | string | string |
@@ -391,3 +398,4 @@ subpaths
391398
| test.cpp:199:9:199:15 | call to strncpy | test.cpp:147:19:147:24 | call to malloc | test.cpp:199:22:199:27 | string | This write may overflow $@ by 2 elements. | test.cpp:199:22:199:27 | string | string |
392399
| test.cpp:203:9:203:15 | call to strncpy | test.cpp:147:19:147:24 | call to malloc | test.cpp:203:22:203:27 | string | This write may overflow $@ by 2 elements. | test.cpp:203:22:203:27 | string | string |
393400
| test.cpp:207:9:207:15 | call to strncpy | test.cpp:147:19:147:24 | call to malloc | test.cpp:207:22:207:27 | string | This write may overflow $@ by 3 elements. | test.cpp:207:22:207:27 | string | string |
401+
| test.cpp:216:3:216:8 | call to memset | test.cpp:220:43:220:48 | call to malloc | test.cpp:216:10:216:10 | p | This write may overflow $@ by 5 elements. | test.cpp:216:10:216:10 | p | p |

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,16 @@ void test5(unsigned size, char *buf, unsigned anotherSize) {
208208
}
209209
}
210210

211+
212+
void *memset(void *, int, unsigned);
213+
214+
void call_memset(void *p, unsigned size)
215+
{
216+
memset(p, 0, size); // GOOD [FALSE POSITIVE]
217+
}
218+
219+
void test_missing_call_context(unsigned char *unrelated_buffer, unsigned size) {
220+
unsigned char* buffer = (unsigned char*)malloc(size);
221+
call_memset(unrelated_buffer, size + 5);
222+
call_memset(buffer, size);
223+
}

0 commit comments

Comments
 (0)