【问题标题】:False negative with address sanitizer?地址消毒剂的假阴性?
【发布时间】:2017-09-17 20:13:39
【问题描述】:

考虑下面的代码。当我使用地址清理程序编译和运行它时,没有显示错误。但是应该有一个错误,即分配/访问超出范围的内存位置?为什么地址消毒剂检测不到?

int arr[30];

int main(){
    arr[40] = 34;
    printf(“%d”, arr[40]);
}

谢谢!

clang -fsanitize=address -fno-omit-frame-pointer test.c
./a.out

【问题讨论】:

    标签: address-sanitizer sanitizer


    【解决方案1】:

    FAQ 中的以下条目对此进行了描述:

    Q: Why didn't ASan report an obviously invalid memory access in my code?
    
    A1: If your errors is too obvious, compiler might have already optimized it 
        out by the time Asan runs.
    
    A2: Another, C-only option is accesses to global common symbols which are
        not protected by Asan (you can use -fno-common to disable generation of
        common symbols and hopefully detect more bugs).
    

    【讨论】:

    • 但即使我将 int arr[30] 设为本地,而不是全局,它也不会引发错误。即使使用 -fno-common 也不会引发错误。
    • 当然,这就是 A1 的答案。基本上,GCC 前端足够“聪明”,可以在 ASan 有机会干预之前尽早丢弃明显不好的访问权限。
    猜你喜欢
    • 2021-03-06
    • 2016-07-28
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 2019-09-05
    • 1970-01-01
    • 2021-03-07
    • 2021-02-08
    相关资源
    最近更新 更多