使用这个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