On Windows 7, I compiled the below snippet with Visual Studio 2008 as a debug project:
{
char bufBef[32];
char buf[8];
char bufAfter[32];
sprintf(buf,"AAAAAAA\0");
buf[8]='\0';
printf("%s\n",buf);
}
Three buffers are adjacent. I find their addresses with a debugger, as follows:
bufBef 0x001afa50
buf 0x001afa40
开发者_高级运维bufAfter 0x001afa18
The statement "buf[8]='\0'" writes the address out of buf. When I run the program, Operating System reported " Debug Error: Run-Time Check Failure #2 - Stack around the variable 'buf' was corrupted."
Then I compiled it as a release project. It run quietly, no error report raised.
My question is how run-time detect buffer overflow?
精彩评论