(base) sv@sv-NF5280M5:/home/sv/桌面$ ./a.out ================================================================= ==1336741==ERROR: AddressSanitizer: heap-use-after-free on address 0x602000000010 at pc 0x55bced57822a bp 0x7ffc50d251d0 sp 0x7ffc50d251c0 WRITE of size 1 at 0x602000000010 thread T0 #00x55bced578229 in main /home/sv/桌面/main.cpp:7 #10x7faf0d998082 in __libc_start_main ../csu/libc-start.c:308 #20x55bced57810d in _start (/home/sv/桌面/a.out+0x110d)
0x602000000010 is located 0 bytes inside of 10-byte region [0x602000000010,0x60200000001a) freed by thread T0 here: #00x7faf0dfbf40f in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:122 #10x55bced5781f5 in main /home/sv/桌面/main.cpp:6 #20x7faf0d998082 in __libc_start_main ../csu/libc-start.c:308
previously allocated by thread T0 here: #00x7faf0dfbf808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144 #10x55bced5781e5 in main /home/sv/桌面/main.cpp:5 #20x7faf0d998082 in __libc_start_main ../csu/libc-start.c:308
SUMMARY: AddressSanitizer: heap-use-after-free /home/sv/桌面/main.cpp:7 in main Shadow bytes around the buggy address: 0x0c047fff7fb0: 00000000000000000000000000000000 0x0c047fff7fc0: 00000000000000000000000000000000 0x0c047fff7fd0: 00000000000000000000000000000000 0x0c047fff7fe0: 00000000000000000000000000000000 0x0c047fff7ff0: 00000000000000000000000000000000 =>0x0c047fff8000: fa fa[fd]fd 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: 01020304050607 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 Shadow gap: cc ==1336741==ABORTING
显然,存在 heap-use-after-free。
仔细分析下上述信息:
1.进程号,错误类型,操作是读,还是写,操作的地址,线程号等,以及栈的回溯信息
1 2 3 4 5
==1336741==ERROR: AddressSanitizer: heap-use-after-free on address 0x602000000010 at pc 0x55bced57822a bp 0x7ffc50d251d0 sp 0x7ffc50d251c0 WRITE of size 1 at 0x602000000010 thread T0 #0 0x55bced578229 in main /home/sv/桌面/main.cpp:7 #1 0x7faf0d998082 in __libc_start_main ../csu/libc-start.c:308 #2 0x55bced57810d in _start (/home/sv/桌面/a.out+0x110d)
0x602000000010 is located 0 bytes inside of 10-byte region [0x602000000010,0x60200000001a) freed by thread T0 here: #0 0x7faf0dfbf40f in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:122 #1 0x55bced5781f5 in main /home/sv/桌面/main.cpp:6 #2 0x7faf0d998082 in __libc_start_main ../csu/libc-start.c:308
3.此块内存区域在那个线程,哪个地方分配的
1 2 3 4
previously allocated by thread T0 here: #0 0x7faf0dfbf808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144 #1 0x55bced5781e5 in main /home/sv/桌面/main.cpp:5 #2 0x7faf0d998082 in __libc_start_main ../csu/libc-start.c:308
(base) sv@sv-NF5280M5:/home/sv/桌面$ ./a.out ================================================================= ==1336960==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000001a at pc 0x5563af190226 bp 0x7fff4fbb4d30 sp 0x7fff4fbb4d20 WRITE of size 1 at 0x60200000001a thread T0 #0 0x5563af190225 in main /home/sv/桌面/main.cpp:6 #1 0x7f88cfff5082 in __libc_start_main ../csu/libc-start.c:308 #2 0x5563af19010d in _start (/home/sv/桌面/a.out+0x110d)
0x60200000001a is located 0 bytes to the right of 10-byte region [0x602000000010,0x60200000001a) allocated by thread T0 here: #0 0x7f88d061c808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144 #1 0x5563af1901e5 in main /home/sv/桌面/main.cpp:5 #2 0x7f88cfff5082 in __libc_start_main ../csu/libc-start.c:308
SUMMARY: AddressSanitizer: heap-buffer-overflow /home/sv/桌面/main.cpp:6 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 00[02]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 Shadow gap: cc ==1336960==ABORTING
================================================================= ==26927==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fffe0389d7a at pc 0x5577fcfd7289 bp 0x7fffe0389d30 sp 0x7fffe0389d20 WRITE of size 1 at 0x7fffe0389d7a thread T0 #0 0x5577fcfd7288 in main /home/thomas/test/ctest/main.c:5 #1 0x7f97e9d0d082 in __libc_start_main ../csu/libc-start.c:308 #2 0x5577fcfd710d in _start (/home/thomas/test/ctest/a.out+0x110d) Address 0x7fffe0389d7a is located in stack of thread T0 at offset 42 in frame #0 0x5577fcfd71d8 in main /home/thomas/test/ctest/main.c:3 This frame has 1 object(s): [32, 42) 'p' (line 4) <== Memory access at offset 42 overflows this variable HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork (longjmp and C++ exceptions *are* supported) SUMMARY: AddressSanitizer: stack-buffer-overflow /home/thomas/test/ctest/main.c:5 in main ...
================================================================= ==27271==ERROR: AddressSanitizer: global-buffer-overflow on address 0x5632b22930aa at pc 0x5632b2290213 bp 0x7ffeba0b5140 sp 0x7ffeba0b5130 WRITE of size 1 at 0x5632b22930aa thread T0 #0 0x5632b2290212 in main /home/thomas/test/ctest/main.c:5 #1 0x7f90fd627082 in __libc_start_main ../csu/libc-start.c:308 #2 0x5632b229010d in _start (/home/thomas/test/ctest/a.out+0x110d) 0x5632b22930aa is located 0 bytes to the right of global variable 'p' defined in'main.c:2:6' (0x5632b22930a0) of size 10 SUMMARY: AddressSanitizer: global-buffer-overflow /home/thomas/test/ctest/main.c:5 in main ...
Direct leak of 4 byte(s) in 1 object(s) allocated from: #0 0x407925 in malloc (/home/sv/桌面/a.out+0x407925) #1 0x426dc1 in foo() /home/sv/桌面/main.cpp:4:23 #2 0x426de3 in main /home/sv/桌面/main.cpp:9:5 #3 0x7f0251d2e082 in __libc_start_main /build/glibc-e2p3jK/glibc-2.31/csu/../csu/libc-start.c:308:16
SUMMARY: LeakSanitizer: 4 byte(s) leaked in 1 allocation(s).