最佳答案
int func(char* str)
{
char buffer[100];
unsigned short len = strlen(str);
if(len >= 100)
{
return (-1);
}
strncpy(buffer,str,strlen(str));
return 0;
}
This code is vulnerable to a buffer overflow attack, and I'm trying to figure out why. I'm thinking it has to do with len
being declared a short
instead of an int
, but I'm not really sure.
Any ideas?