File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
cpp/ql/test/query-tests/Security/CWE/CWE-119/semmle/tests Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 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. |
Original file line number Diff line number Diff 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+
589606int 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}
You can’t perform that action at this time.
0 commit comments