Skip to content

Commit c15ebf8

Browse files
committed
C++: Add testcase with FP (and also fix an incorrect test annotation).
1 parent 2206216 commit c15ebf8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ edges
8484
| test.cpp:243:16:243:21 | string indirection | test.cpp:243:12:243:21 | string |
8585
| test.cpp:249:20:249:27 | call to my_alloc | test.cpp:250:12:250:12 | p |
8686
| test.cpp:256:17:256:22 | call to malloc | test.cpp:257:12:257:12 | p |
87+
| test.cpp:262:22:262:27 | call to malloc | test.cpp:266:12:266:12 | p |
88+
| test.cpp:264:20:264:25 | call to malloc | test.cpp:266:12:266:12 | p |
8789
nodes
8890
| test.cpp:16:11:16:21 | mk_string_t indirection [string] | semmle.label | mk_string_t indirection [string] |
8991
| test.cpp:18:5:18:30 | ... = ... | semmle.label | ... = ... |
@@ -162,6 +164,9 @@ nodes
162164
| test.cpp:250:12:250:12 | p | semmle.label | p |
163165
| test.cpp:256:17:256:22 | call to malloc | semmle.label | call to malloc |
164166
| test.cpp:257:12:257:12 | p | semmle.label | p |
167+
| test.cpp:262:22:262:27 | call to malloc | semmle.label | call to malloc |
168+
| test.cpp:264:20:264:25 | call to malloc | semmle.label | call to malloc |
169+
| test.cpp:266:12:266:12 | p | semmle.label | p |
165170
subpaths
166171
| 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] |
167172
#select
@@ -182,3 +187,4 @@ subpaths
182187
| 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 |
183188
| 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 |
184189
| 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 |
190+
| test.cpp:266:5:266:10 | call to memset | test.cpp:262:22:262:27 | call to malloc | test.cpp:266:12:266:12 | p | This write may overflow $@ by 1 element. | test.cpp:266:12:266:12 | p | p |

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void *memset(void *, int, unsigned);
213213

214214
void call_memset(void *p, unsigned size)
215215
{
216-
memset(p, 0, size); // GOOD [FALSE POSITIVE]
216+
memset(p, 0, size); // GOOD
217217
}
218218

219219
void test_missing_call_context(unsigned char *unrelated_buffer, unsigned size) {
@@ -256,4 +256,12 @@ void test6(unsigned long n, char *p) {
256256
p = (char *)malloc(n);
257257
memset(p, 0, n); // GOOD
258258
}
259+
}
260+
261+
void test7(unsigned n) {
262+
char* p = (char*)malloc(n);
263+
if(!p) {
264+
p = (char*)malloc(++n);
265+
}
266+
memset(p, 0, n); // GOOD [FALSE POSITIVE]
259267
}

0 commit comments

Comments
 (0)