Chinaunix首页 | 论坛 | 博客
  • 博客访问: 33214
  • 博文数量: 15
  • 博客积分: 351
  • 博客等级: 一等列兵
  • 技术积分: 105
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-22 12:34
文章分类

全部博文(15)

文章存档

2011年(15)

我的朋友

分类: C/C++

2011-10-04 14:49:23

用mudflap检测“stack/bbs上的变量访问错误”

1. 安装mudflap
#yum install libmudflap libmudflap-devel

2. 示例代码
test_44.c
  1. static char onbss[128];

  2. int main( int argc , char **argv )
  3. {
  4.     char onstack[128] = {0};
  5.     int dummy;
  6.     
  7.     dummy = onbss[128];        // off-by-one bug
  8.     dummy = onstack[128];    //ditto
  9.     
  10.     return 0;
  11. }
3. 编译
gcc -g -fmudflap -o testflap test_44.c -lmudflap

4. 输出
[root@localhost helloworld]# ./testflap
*******
mudflap violation 1 (check/read): time=1317740344.659364 ptr=0x80c9c40 size=129
pc=0x1dca8d location=`test_44.c:8:2 (main)'
      /usr/lib/libmudflap.so.0(__mf_check+0x3d) [0x1dca8d]
      ./testflap(main+0x113) [0x8048807]
      /usr/lib/libmudflap.so.0(__wrap_main+0x4f) [0x1dc28f]
Nearby object 1: checked region begins 0B into and ends 1B after
mudflap object 0x96711e8: name=`test_44.c:1:13 onbss'
bounds=[0x80c9c40,0x80c9cbf] size=128 area=static check=3r/0w liveness=3
alloc time=1317740344.659190 pc=0x1dc22d
number of nearby objects: 1
*******
mudflap violation 2 (check/read): time=1317740344.696388 ptr=0xbfbfba38 size=129
pc=0x1dca8d location=`test_44.c:9:2 (main)'
      /usr/lib/libmudflap.so.0(__mf_check+0x3d) [0x1dca8d]
      ./testflap(main+0x1c0) [0x80488b4]
      /usr/lib/libmudflap.so.0(__wrap_main+0x4f) [0x1dc28f]
Nearby object 1: checked region begins 0B into and ends 1B after
mudflap object 0x9672110: name=`test_44.c:5:7 (main) onstack'
bounds=[0xbfbfba38,0xbfbfbab7] size=128 area=stack check=3r/0w liveness=3
alloc time=1317740344.659339 pc=0x1dc22d
number of nearby objects: 1
阅读(1581) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

xukeys2011-10-04 15:09:02

参考
1. Mudflap Pointer Debugging
http://gcc.gnu.org/wiki/Mudflap_Pointer_Debugging