#include <stdio.h>
main()
{
char buf[8];
sprintf(buf,"AAAA%3s","XXssssssssXXXsssssXXX");
printf("%s\n",buf);
}
I expected valgrind to detect a buffer overflow with the above code. But it does not report any errors or warnings. Do I need to enable any special flags for that?
gcc
orclang
compiler, you could compile with-Wall -g -fsanitize=address
and it might give a message at runtime. BTWsprintf
is intrinsically unsafe and should not be used. Usesnprintf
orasprintf
– Spectroscopy