zoukankan      html  css  js  c++  java
  • 在使用asan的时候,如果我们想关闭/取消:useafterpoision 检测

    使用这个allow_user_poisoning=0,来取消

    以这个例子为例:

    // example1.cpp
    // use-after-poison error
    #include <stdlib.h>
    
    extern "C" void __asan_poison_memory_region(void *, size_t);
    
    int main(int argc, char **argv) {
        char *x = new char[16];
        x[10] = 0;
        __asan_poison_memory_region(x, 16);
    
        int res = x[argc * 10];              // Boom!
     
        delete [] x;
        return res;
    }
    
    gcc -fsanitize=address  eaxmple1.cpp -o ufpexe
    

    运行会报错:

    =================================================================
    ==9369==ERROR: AddressSanitizer: use-after-poison on address 0x60200000001a at pc 0x5635fbfa99f2 bp 0x7fffc5a981d0 sp 0x7fffc5a981c0
    READ of size 1 at 0x60200000001a thread T0
        #0 0x5635fbfa99f1 in main (/home/xijun.gong/x86_64-linux-rel/tops/system_test/model_test/topsinference_test/a.out+0x9f1)
        #1 0x7f5e429f5bf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
        #2 0x5635fbfa9859 in _start (/home/xijun.gong/x86_64-linux-rel/tops/system_test/model_test/topsinference_test/a.out+0x859)
    
    0x60200000001a is located 10 bytes inside of 16-byte region [0x602000000010,0x602000000020)
    allocated by thread T0 here:
        #0 0x7f5e42ea5608 in operator new[](unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe0608)
        #1 0x5635fbfa9952 in main (/home/xijun.gong/x86_64-linux-rel/tops/system_test/model_test/topsinference_test/a.out+0x952)
        #2 0x7f5e429f5bf6 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6)
    
    SUMMARY: AddressSanitizer: use-after-poison (/home/xijun.gong/x86_64-linux-rel/tops/system_test/model_test/topsinference_test/a.out+0x9f1) in main
    Shadow bytes around the buggy address:
      0x0c047fff7fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0c047fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0c047fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0c047fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0c047fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    =>0x0c047fff8000: fa fa f7[f7]fa fa fa fa fa fa fa fa fa fa fa fa
      0x0c047fff8010: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0c047fff8020: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0c047fff8030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0c047fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0c047fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
    Shadow byte legend (one shadow byte represents 8 application bytes):
      Addressable:           00
      Partially addressable: 01 02 03 04 05 06 07
      Heap left redzone:       fa
      Freed heap region:       fd
      Stack left redzone:      f1
      Stack mid redzone:       f2
      Stack right redzone:     f3
      Stack after return:      f5
      Stack use after scope:   f8
      Global redzone:          f9
      Global init order:       f6
      Poisoned by user:        f7
      Container overflow:      fc
      Array cookie:            ac
      Intra object redzone:    bb
      ASan internal:           fe
      Left alloca redzone:     ca
      Right alloca redzone:    cb
    ==9369==ABORTING

    这样运行会取消掉:

    ASAN_OPTIONS=allow_user_poisoning=0  ./exeamp
    

      

    编程是一种快乐,享受代码带给我的乐趣!!!
  • 相关阅读:
    64win7+64Oracle+32plsql
    Delphi与Java中的日期互换
    QT变异版本下载(SJLJ长跳转,DWARF不传递错误(32位专用),SEH(64位专用)),以及QT的实验室项目
    顿悟,职业生涯最重要的是行业水平的积累,而不是多学某一门语言(很危险)——遥想铁血强人刘志军对铁路行业的理解以及执行力
    天下古今之庸人,皆以一惰字致败(联想到了自己的高考数学大题)
    这七种情况下,不要创业
    Android 点击桌面快捷方式和Notifycation跳转到Task栈顶Activity
    字符串模式匹配算法——BM、Horspool、Sunday、KMP、KR、AC算法一网打尽
    QSplashScreen开机画面(不断的repaint)
    一个QT 3D转动控件
  • 原文地址:https://www.cnblogs.com/gongxijun/p/15512814.html
Copyright © 2011-2022 走看看