开发者

How run-time detect buffer overflow?

Merged with How run-time detects buffer overflow?.

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜