In my project one of the command-line arguments is loaded into a C99 VLA (variable-length array) as shown in the example code below.
My question is: can this be exploited? If yes, I'd like to be shown how and also how to patch it.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
if (argc != 2)
return EXIT_FAILURE;
char msg[strlen(argv[1]) + 1];
strcpy(msg, argv[1]);
printf("%s\n", msg);
return EXIT_SUCCESS;
}
I am torn between keeping the current code (which I believe is quite elegant) and using
– user102756 Apr 17 '16 at 19:20FILENAME_MAXwith bounds-checked string functions from C11.