-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
Description
This badly bounded write query flags the following code incorrectly:
#include <stdio.h>
#include <stdlib.h>
char* dest = "a";
int main(int argc, char* argv[])
{
const char src[] = "Testing testing 123";
dest = malloc(sizeof(src));
if (dest == 0)
return EXIT_FAILURE;
snprintf(dest, sizeof(src), "%s", src);
fprintf(stdout, "%s\n", dest);
return EXIT_SUCCESS;
}
The snprintf
is flagged:
| bw | col1 |
+------------------+-----------------------------------------------------------------------------------------------+
| call to snprintf | This 'call to snprintf' operation is limited to 20 bytes but the destination is only 0 bytes. |
| call to snprintf | This 'call to snprintf' operation is limited to 20 bytes but the destination is only 2 bytes. |
Admittedly, the code is doing something slightly strange (that is, taking a pointer that was pointing to a string constant, and repointing it at dynamically allocated memory). However, I don't think the finding is correct.