I was just marked down on coursework for this incorrect solution to a buffer overflow in c but was not provided feedback on how it was wrong. Could somebody let me know what the problem is? Thank you.
The question stated to provide a solution in case a longer string than 16 was passed in to this function:
void function(char *str)
{
char buffer[16];
strcpy(buffer, str);
}
And here is my solution
void function(char *str)
{
size_t str_length = strlen(str);
char buffer[str_length];
strcpy(buffer, str);
}
Thanks