Skip to content

Commit a09a8db

Browse files
committed
C++: Add testcase with repeated TP alerts.
1 parent 4035b16 commit a09a8db

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ edges
212212
| test.cpp:214:24:214:24 | p | test.cpp:216:10:216:10 | p |
213213
| test.cpp:220:43:220:48 | call to malloc | test.cpp:222:15:222:20 | buffer |
214214
| test.cpp:222:15:222:20 | buffer | test.cpp:214:24:214:24 | p |
215+
| test.cpp:228:43:228:48 | call to malloc | test.cpp:232:10:232:15 | buffer |
215216
nodes
216217
| test.cpp:16:11:16:21 | mk_string_t indirection [string] | semmle.label | mk_string_t indirection [string] |
217218
| test.cpp:18:5:18:30 | ... = ... | semmle.label | ... = ... |
@@ -381,6 +382,8 @@ nodes
381382
| test.cpp:216:10:216:10 | p | semmle.label | p |
382383
| test.cpp:220:43:220:48 | call to malloc | semmle.label | call to malloc |
383384
| test.cpp:222:15:222:20 | buffer | semmle.label | buffer |
385+
| test.cpp:228:43:228:48 | call to malloc | semmle.label | call to malloc |
386+
| test.cpp:232:10:232:15 | buffer | semmle.label | buffer |
384387
subpaths
385388
#select
386389
| 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 |
@@ -399,3 +402,35 @@ subpaths
399402
| 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 |
400403
| 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 |
401404
| 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 |
405+
| 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 1 element. | test.cpp:232:10:232:15 | buffer | buffer |
406+
| 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 2 elements. | test.cpp:232:10:232:15 | buffer | buffer |
407+
| 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 3 elements. | test.cpp:232:10:232:15 | buffer | buffer |
408+
| 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 4 elements. | test.cpp:232:10:232:15 | buffer | buffer |
409+
| 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 5 elements. | test.cpp:232:10:232:15 | buffer | buffer |
410+
| 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 6 elements. | test.cpp:232:10:232:15 | buffer | buffer |
411+
| 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 7 elements. | test.cpp:232:10:232:15 | buffer | buffer |
412+
| 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 8 elements. | test.cpp:232:10:232:15 | buffer | buffer |
413+
| 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 9 elements. | test.cpp:232:10:232:15 | buffer | buffer |
414+
| 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 10 elements. | test.cpp:232:10:232:15 | buffer | buffer |
415+
| 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 11 elements. | test.cpp:232:10:232:15 | buffer | buffer |
416+
| 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 12 elements. | test.cpp:232:10:232:15 | buffer | buffer |
417+
| 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 13 elements. | test.cpp:232:10:232:15 | buffer | buffer |
418+
| 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 14 elements. | test.cpp:232:10:232:15 | buffer | buffer |
419+
| 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 15 elements. | test.cpp:232:10:232:15 | buffer | buffer |
420+
| 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 16 elements. | test.cpp:232:10:232:15 | buffer | buffer |
421+
| 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 17 elements. | test.cpp:232:10:232:15 | buffer | buffer |
422+
| 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 18 elements. | test.cpp:232:10:232:15 | buffer | buffer |
423+
| 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 19 elements. | test.cpp:232:10:232:15 | buffer | buffer |
424+
| 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 20 elements. | test.cpp:232:10:232:15 | buffer | buffer |
425+
| 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 21 elements. | test.cpp:232:10:232:15 | buffer | buffer |
426+
| 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 22 elements. | test.cpp:232:10:232:15 | buffer | buffer |
427+
| 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 23 elements. | test.cpp:232:10:232:15 | buffer | buffer |
428+
| 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 24 elements. | test.cpp:232:10:232:15 | buffer | buffer |
429+
| 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 25 elements. | test.cpp:232:10:232:15 | buffer | buffer |
430+
| 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 26 elements. | test.cpp:232:10:232:15 | buffer | buffer |
431+
| 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 27 elements. | test.cpp:232:10:232:15 | buffer | buffer |
432+
| 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 28 elements. | test.cpp:232:10:232:15 | buffer | buffer |
433+
| 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 29 elements. | test.cpp:232:10:232:15 | buffer | buffer |
434+
| 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 30 elements. | test.cpp:232:10:232:15 | buffer | buffer |
435+
| 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 31 elements. | test.cpp:232:10:232:15 | buffer | buffer |
436+
| 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 |

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,14 @@ void test_missing_call_context(unsigned char *unrelated_buffer, unsigned size) {
220220
unsigned char* buffer = (unsigned char*)malloc(size);
221221
call_memset(unrelated_buffer, size + 5);
222222
call_memset(buffer, size);
223+
}
224+
225+
bool unknown();
226+
227+
void repeated_alerts(unsigned size, unsigned offset) {
228+
unsigned char* buffer = (unsigned char*)malloc(size);
229+
while(unknown()) {
230+
++size;
231+
}
232+
memset(buffer, 0, size); // BAD
223233
}

0 commit comments

Comments
 (0)