用mudflap检测“stack/bbs上的变量访问错误”
1. 安装mudflap
#yum install libmudflap libmudflap-devel
2. 示例代码
test_44.c
- static char onbss[128];
-
-
int main( int argc , char **argv )
-
{
-
char onstack[128] = {0};
-
int dummy;
-
-
dummy = onbss[128]; // off-by-one bug
-
dummy = onstack[128]; //ditto
-
-
return 0;
-
}
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) |