Skip to content

Commit df9981d

Browse files
committed
C++: Add testcases with false positives.
1 parent ae6326b commit df9981d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-119/semmle/tests/OverflowStatic.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
| tests.cpp:245:42:245:42 | 6 | Potential buffer-overflow: 'global_array_5' has size 5 not 6. |
66
| tests.cpp:349:2:349:14 | access to array | Potential buffer-overflow: 'charArray' has size 10 but 'charArray[10]' is accessed here. |
77
| tests.cpp:350:17:350:29 | access to array | Potential buffer-overflow: 'charArray' has size 10 but 'charArray[10]' is accessed here. |
8+
| tests.cpp:594:4:594:12 | access to array | Potential buffer-overflow: counter 'k' <= 100 but 'buffer' has 16 elements. |
9+
| tests.cpp:603:24:603:24 | n | Potential buffer-overflow: 'dest' has size 128 not 132. |
810
| var_size_struct.cpp:54:5:54:14 | access to array | Potential buffer-overflow: 'str' has size 1 but 'str[1]' is accessed here. |
911
| var_size_struct.cpp:55:5:55:14 | access to array | Potential buffer-overflow: 'str' has size 1 but 'str[1]' is accessed here. |
1012
| var_size_struct.cpp:103:39:103:41 | 129 | Potential buffer-overflow: 'str' has size 128 not 129. |

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,23 @@ void test21(bool cond)
586586
if (ptr[-1] == 0) { return; } // GOOD: accesses buffer[1]
587587
}
588588

589+
void test22(bool b, const char* source) {
590+
char buffer[16];
591+
int k;
592+
for (k = 0; k <= 100; k++) {
593+
if(k < 16) {
594+
buffer[k] = 'x'; // GOOD [FALSE POSITIVE]
595+
}
596+
}
597+
598+
char dest[128];
599+
int n = b ? 1024 : 132;
600+
if (n >= 128) {
601+
return;
602+
}
603+
memcpy(dest, source, n); // GOOD [FALSE POSITIVE]
604+
}
605+
589606
int main(int argc, char *argv[])
590607
{
591608
long long arr17[19];
@@ -609,6 +626,7 @@ int main(int argc, char *argv[])
609626
test19(argc == 0);
610627
test20();
611628
test21(argc == 0);
629+
test22(argc == 0, argv[0]);
612630

613631
return 0;
614632
}

0 commit comments

Comments
 (0)