GCC 缺少 AddressSanitizer 错误位置

AddressSanitizer Error Location Missing with GCC

提问人:gopher 提问时间:11/1/2023 最后编辑:gopher 更新时间:11/1/2023 访问量:69

问:

此命令不显示 AddressSanitizer 摘要错误位置。gcc uaf.c -o uaf -fsanitize=address -static-libasan

代码如下:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main(int argc, const char *argv[]) {
    char *s = malloc(100);
    free(s);
    strcpy(s, "Hello world!");
    printf("string is: %s\n", s);
    return 0;
}

这是我所看到的:

 =================================================================
    ==1017908==ERROR: AddressSanitizer: heap-use-after-free on address 0x60b0000000f0 at pc 0x5623a332bb53 bp 0x7fff85504890 sp 0x7fff85504038
    WRITE of size 13 at 0x60b0000000f0 thread T0
        #0 0x5623a332bb52 in memcpy (/home/test/work/uaf+0x1db52)
        #1 0x5623a33ebcd5 in main (/home/test/work/uaf+0xddcd5)
        #2 0x7f226558ad8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f)
        #3 0x7f226558ae3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f)
        #4 0x5623a33163a4 in _start (/home/test/work/uaf+0x83a4)
    
    0x60b0000000f0 is located 0 bytes inside of 100-byte region [0x60b0000000f0,0x60b000000154)
    freed by thread T0 here:
        #0 0x5623a33a5da7 in free (/home/test/work/uaf+0x97da7)
        #1 0x5623a33ebcba in main (/home/test/work/uaf+0xddcba)
        #2 0x7f226558ad8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f)
    
    previously allocated by thread T0 here:
        #0 0x5623a33a60f7 in malloc (/home/test/work/uaf+0x980f7)
        #1 0x5623a33ebcaa in main (/home/test/work/uaf+0xddcaa)
        #2 0x7f226558ad8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f)
    
    SUMMARY: AddressSanitizer: heap-use-after-free (/home/test/work/uaf+0x1db52) in memcpy
Shadow bytes around the buggy address:

这是我在摘要部分所期望的:

SUMMARY: AddressSanitizer: heap-use-after-free /home/test/work/uaf.c:8 in memcpy

我在这里错过了什么?

我正在使用这个博客作为参考 https://www.osc.edu/resources/getting_started/howto/howto_use_address_sanitizer

c gcc 警告 地址-消毒剂

评论

3赞 n. m. could be an AI 11/1/2023
-g显然地。线号信息还从何而来?
0赞 gopher 11/1/2023
@n.m.couldbeanAI,谢谢我试过了,后者给出了更好的结果......不太确定为什么必须删除gcc uaf.c -o uaf -fsanitize=address -static-libasan -ggcc uaf.c -o uaf -fsanitize=address -g-static-libasan
0赞 273K 11/1/2023
标题中的CC是什么?顺便说一句,标签 C++ 使用不当,显示的代码是无效的 C++ 并且无法编译。
0赞 273K 11/1/2023
无法重现 godbolt.org/z/4rseaqv8v。您似乎运行了一个旧的 gcc/address 清理器,该清理器需要与其符号化器一起运行。
0赞 gopher 11/1/2023
CC 是错别字,应该是 gcc

答: 暂无答案