在使用asan的时候,如果我们想关闭/取消:use-after-poision 检测
使用这个allow_user_poisoning=0,来取消
以这个例子为例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | // 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; } |
1 | 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
这样运行会取消掉:
1 | ASAN_OPTIONS=allow_user_poisoning=0 ./exeamp |
编程是一种快乐,享受代码带给我的乐趣!!!
分类:
c++
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 字符编码:从基础到乱码解决
2014-11-05 hdu 1598 find the most comfortable road(枚举+卡鲁斯卡尔最小生成树)
2014-11-05 杂记(编程style)----google code style!