作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
#include <iostream>
#include <string.h>
using namespace std;
//void test3(char*) __attribute__((no_sanitize_address));
//__attribute__((no_sanitize_address))
void test3(char *p){
delete[] p;
cout << *p << endl;
cout << "test3" << endl;
}
//__attribute__((no_sanitize_address))
void test2(char *ptr, char *p){
if(memcmp(ptr,p,6) == 0){
cout << "Yes" << endl;
}
cout << "test2" << endl;
}
int main(){
char *p = new char[5];
char *ptr = new char[6];
test2(ptr, p);
test3(p);
delete[] ptr;
return 0;
}
编译标志是
-fsanitize=address -fno-omit-frame-pointer -fsanitize-recover=address -g -pipe -rdynamic -Wl,--build-id
.
rpmbuild
构建下面的 rpm 包:
Wrote: /root/rpmbuild/RPMS/x86_64/main_test-1.0.0-1.x86_64.rpm
Wrote: /root/rpmbuild/RPMS/x86_64/main_test-debuginfo-1.0.0-1.x86_64.rpm
安装后
main_test
和
main_test-debuginfo
, 我跑
main
.现在的问题是 Asan 不报告任何源文件行。
=================================================================
==39137==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000eff5 at pc 0x7ffff6ecd328 bp 0x7fffffffe350 sp 0x7fffffffdb00
READ of size 6 at 0x60200000eff5 thread T0
#0 0x7ffff6ecd327 (/usr/lib64/libasan.so.3+0x8d327)
#1 0x400ee2 in test2(char*, char*) (/usr/local/bin/main+0x400ee2)
#2 0x400f58 in main (/usr/local/bin/main+0x400f58)
#3 0x7ffff62763d4 in __libc_start_main (/usr/lib64/libc.so.6+0x223d4)
#4 0x400d58 (/usr/local/bin/main+0x400d58)
0x60200000eff5 is located 0 bytes to the right of 5-byte region [0x60200000eff0,0x60200000eff5)
allocated by thread T0 here:
#0 0x7ffff6f02e70 in operator new[](unsigned long) (/usr/lib64/libasan.so.3+0xc2e70)
#1 0x400f33 in main (/usr/local/bin/main+0x400f33)
#2 0x7ffff62763d4 in __libc_start_main (/usr/lib64/libc.so.6+0x223d4)
SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib64/libasan.so.3+0x8d327)
...
然而,期望是:
=================================================================
==36210==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000eff5 at pc 0x7ffff6ecd328 bp 0x7fffffffe370 sp 0x7fffffffdb20
READ of size 6 at 0x60200000eff5 thread T0
#0 0x7ffff6ecd327 (/usr/lib64/libasan.so.3+0x8d327)
#1 0x400ee2 in test2(char*, char*) /home/matt/main_test-1.0.0/main.cpp:17
#2 0x400f58 in main /home/matt/main_test-1.0.0/main.cpp:27
#3 0x7ffff62763d4 in __libc_start_main (/usr/lib64/libc.so.6+0x223d4)
#4 0x400d58 (/home/matt/main_test-1.0.0/main+0x400d58)
0x60200000eff5 is located 0 bytes to the right of 5-byte region [0x60200000eff0,0x60200000eff5)
allocated by thread T0 here:
#0 0x7ffff6f02e70 in operator new[](unsigned long) (/usr/lib64/libasan.so.3+0xc2e70)
#1 0x400f33 in main /home/matt/main_test-1.0.0/main.cpp:24
#2 0x7ffff62763d4 in __libc_start_main (/usr/lib64/libc.so.6+0x223d4)
SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib64/libasan.so.3+0x8d327)
...
似乎Asan无法链接源文件。我对出了什么问题感到困惑。有什么办法可以解决吗?
最佳答案
I'm confused with what went wrong.
Is there any way to solve it?
strip
并在 rpmbuild
中单独生成调试信息. This answer可能有用。 addr2line -fe /path/to/unstripped/binary 0x400ee2 0x400f58 ...
事后恢复源文件/行信息。 关于linux - 地址 sanitizer : No matching source file lines in the report after separating debuginfo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69387584/
我是一名优秀的程序员,十分优秀!