File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed
cpp/ql/test/query-tests/Security/CWE/CWE-131/semmle/NoSpaceForZeroTerminator Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change 11| test.c:15:20:15:25 | call to malloc | This allocation does not include space to null-terminate the string. |
22| test.c:29:20:29:25 | call to malloc | This allocation does not include space to null-terminate the string. |
33| test.c:44:20:44:25 | call to malloc | This allocation does not include space to null-terminate the string. |
4+ | test.c:72:17:72:22 | call to malloc | This allocation does not include space to null-terminate the string. |
45| test.cpp:18:35:18:40 | call to malloc | This allocation does not include space to null-terminate the string. |
Original file line number Diff line number Diff line change @@ -63,3 +63,15 @@ void good3(char *str) {
6363 char * buffer = malloc ((strlen (str ) + 1 ) * sizeof (char ));
6464 free (buffer );
6565}
66+
67+ void * memcpy (void * s1 , const void * s2 , size_t n );
68+
69+ void good4 (char * str ) {
70+ // GOOD -- allocating a non zero-terminated string [FALSE POSITIVE]
71+ int len = strlen (str );
72+ char * buffer = malloc (len );
73+
74+ memcpy (buffer , str , len );
75+
76+ free (buffer );
77+ }
You can’t perform that action at this time.
0 commit comments