Skip to content

Commit 92a730c

Browse files
committed
C++: Add a false positive.
1 parent 96a32c0 commit 92a730c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ edges
7070
| test.cpp:262:15:262:30 | call to malloc | test.cpp:266:12:266:12 | p | provenance | |
7171
| test.cpp:264:9:264:30 | ... = ... | test.cpp:266:12:266:12 | p | provenance | |
7272
| test.cpp:264:13:264:30 | call to malloc | test.cpp:264:9:264:30 | ... = ... | provenance | |
73+
| test.cpp:271:14:271:27 | new[] | test.cpp:271:14:271:27 | new[] | provenance | |
74+
| test.cpp:271:14:271:27 | new[] | test.cpp:276:12:276:13 | xs | provenance | |
7375
nodes
7476
| test.cpp:16:11:16:21 | **mk_string_t [string] | semmle.label | **mk_string_t [string] |
7577
| test.cpp:18:5:18:7 | *str [post update] [string] | semmle.label | *str [post update] [string] |
@@ -151,6 +153,9 @@ nodes
151153
| test.cpp:264:9:264:30 | ... = ... | semmle.label | ... = ... |
152154
| test.cpp:264:13:264:30 | call to malloc | semmle.label | call to malloc |
153155
| test.cpp:266:12:266:12 | p | semmle.label | p |
156+
| test.cpp:271:14:271:27 | new[] | semmle.label | new[] |
157+
| test.cpp:271:14:271:27 | new[] | semmle.label | new[] |
158+
| test.cpp:276:12:276:13 | xs | semmle.label | xs |
154159
subpaths
155160
| test.cpp:242:22:242:27 | buffer | test.cpp:235:40:235:45 | buffer | test.cpp:235:27:235:31 | *p_str [Return] [string] | test.cpp:242:16:242:19 | set_string output argument [string] |
156161
| test.cpp:242:22:242:27 | buffer | test.cpp:235:40:235:45 | buffer | test.cpp:235:27:235:31 | *p_str [string] | test.cpp:242:16:242:19 | set_string output argument [string] |
@@ -173,3 +178,4 @@ subpaths
173178
| test.cpp:243:5:243:10 | call to memset | test.cpp:241:20:241:38 | 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 |
174179
| test.cpp:250:5:250:10 | call to memset | test.cpp:249:14:249:33 | 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 |
175180
| test.cpp:266:5:266:10 | call to memset | test.cpp:262:15:262:30 | 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 |
181+
| test.cpp:276:5:276:10 | call to memset | test.cpp:271:14:271:27 | new[] | test.cpp:276:12:276:13 | xs | This write may overflow $@ by 1 element. | test.cpp:276:12:276:13 | xs | xs |

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,15 @@ void test7(unsigned n) {
264264
p = (char*)malloc(++n);
265265
}
266266
memset(p, 0, n); // GOOD [FALSE POSITIVE]
267+
}
268+
269+
void test8(unsigned size, unsigned src_pos)
270+
{
271+
char *xs = new char[size];
272+
if (src_pos > size) {
273+
src_pos = size;
274+
}
275+
if (src_pos < size - 1) {
276+
memset(xs, 0, src_pos + 1); // GOOD [FALSE POSITIVE]
277+
}
267278
}

0 commit comments

Comments
 (0)