记一个AddressSanitizer(ASAN)linux下的内存分析神器的问题

感谢万能的互联网,我向google提出的issue很快就得到了工程师回复,解决了我的问题。

我的问题是这样的:

AddressSanitizer can't detect some global buffer overflow!  #1285

 Closed

yangyongzhen opened this issue yesterday · 1 comment

yangyongzhen commented yesterday

what a pity! AddressSanitizer can't detect some global buffer overflow! Even if the mistake or code bugs is so obvious。

for example,this code bellow, guess what you will get,
......

U08 IP[10];
U08 IP1[10];
int main()
{
    
    memset(IP1,0x3A,10);
    memcpy(IP,"123456789021111111111",17);
    IP[15] = 12;

    printf("IP1[0]:%d\n",IP1[0]);
    printf("IP1[1]:%d\n",IP1[1]);
    printf("IP1[2]:%d\n",IP1[2]);

    printf("IP[10]:%d\n",IP[10]);
    printf("IP[11]:%d\n",IP[11]);
    printf("IP[15]:%d\n",IP[15]);

    printf("IP1[0]:%d\n",IP1[0]);
    printf("IP1[1]:%d\n",IP1[1]);
    printf("IP1[2]:%d\n",IP1[2]);
}

。。。。。。

use cflags= -std=gnu99 -Wall -fno-stack-protector -fno-omit-frame-pointer -fvar-tracking -g2 -fno-inline -fsanitize=address -fexceptions

but AddressSanitizer can't detect this!!!

if you add "static" before the global vars,like this: static U08 IP[10];
then AddressSanitizer can detect mistakes,, why?

melver commented 23 hours ago

Add -fno-common for C code. Globals that are placed in the common section (default for C) won't be separated by redzones, and therefore the OOB accesses in your example simply access IP1's memory.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

特立独行的猫a

您的鼓励是我的创作动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值