美文网首页
AddressSanitizer 简介和示例

AddressSanitizer 简介和示例

作者: 付凯强 | 来源:发表于2024-06-30 20:46 被阅读0次

    AddressSanitizer 是检测C/C++内存错误的工具。
    这个工具很快。插入指令的程序的平均速度减慢约为2倍(请参阅AddressSanitizerPerformance Numbers)。
    该工具由一个编译器指令插入模块(目前为LLVM传递)和一个替换malloc函数的运行时库组成。
    该工具适用于x86、ARM、MIPS(所有体系结构的32位和64位版本)、PowerPC64。支持的操作系统有Linux、Darwin(OS X和iOS模拟器)、FreeBSD、Android。

    编译配置

    export ASAN_OPTIONS=check_initialization_order=true:strict_init_order=true:detect_stack_use_after_return=1
    

    释放后使用 heap-use-after-free

    g++ main.cpp -o main -fsanitize=address -g -fno-omit-frame-pointer
    

    main.cpp

    #include <iostream>
    
    int main(int argc, char **argv) {
        int *array = new int[100];
        delete [] array;
        return array[argc];  // BOOM
    }
    
    $./main
    =================================================================
    ==253799==ERROR: AddressSanitizer: heap-use-after-free on address 0x614000000044 at pc 0x558fc320e309 bp 0x7ffc3c6a3260 sp 0x7ffc3c6a3250
    READ of size 4 at 0x614000000044 thread T0
        #0 0x558fc320e308 in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:6
        #1 0x7f0df87c9082 in __libc_start_main ../csu/libc-start.c:308
        #2 0x558fc320e1cd in _start (/home/fukaiqiang/src/code/CPLUS_HASHMAP/main+0x11cd)
    
    0x614000000044 is located 4 bytes inside of 400-byte region [0x614000000040,0x6140000001d0)
    freed by thread T0 here:
        #0 0x7f0df8df36ef in operator delete[](void*) ../../../../src/libsanitizer/asan/asan_new_delete.cc:168
        #1 0x558fc320e2bc in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:5
        #2 0x7f0df87c9082 in __libc_start_main ../csu/libc-start.c:308
    
    previously allocated by thread T0 here:
        #0 0x7f0df8df2787 in operator new[](unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cc:107
        #1 0x558fc320e2a5 in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:4
        #2 0x7f0df87c9082 in __libc_start_main ../csu/libc-start.c:308
    
    SUMMARY: AddressSanitizer: heap-use-after-free /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:6 in main
    Shadow bytes around the buggy address:
      0x0c287fff7fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0c287fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0c287fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0c287fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0c287fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    =>0x0c287fff8000: fa fa fa fa fa fa fa fa[fd]fd fd fd fd fd fd fd
      0x0c287fff8010: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x0c287fff8020: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      0x0c287fff8030: fd fd fd fd fd fd fd fd fd fd fa fa fa fa fa fa
      0x0c287fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0c287fff8050: 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
    ==253799==ABORTING
    
    

    堆缓冲区溢出 heap-buffer-overflow

    g++ main.cpp -o main -fsanitize=address -g -fno-omit-frame-pointer
    

    main.cpp

    #include <iostream>
    
    int main(int argc, char **argv) {
        int *array = new int[100];
        array[0] = 0;
        int res = array[argc + 100];  // BOOM
        delete [] array;
        return res;
    }
    
    $./main
    =================================================================
    ==253933==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6140000001d4 at pc 0x56361465435b bp 0x7ffca4f01170 sp 0x7ffca4f01160
    READ of size 4 at 0x6140000001d4 thread T0
        #0 0x56361465435a in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:6
        #1 0x7fa7e4f60082 in __libc_start_main ../csu/libc-start.c:308
        #2 0x5636146541ed in _start (/home/fukaiqiang/src/code/CPLUS_HASHMAP/main+0x11ed)
    
    0x6140000001d4 is located 4 bytes to the right of 400-byte region [0x614000000040,0x6140000001d0)
    allocated by thread T0 here:
        #0 0x7fa7e5589787 in operator new[](unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cc:107
        #1 0x5636146542c5 in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:4
        #2 0x7fa7e4f60082 in __libc_start_main ../csu/libc-start.c:308
    
    SUMMARY: AddressSanitizer: heap-buffer-overflow /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:6 in main
    Shadow bytes around the buggy address:
      0x0c287fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0c287fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0c287fff8000: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
      0x0c287fff8010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0c287fff8020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    =>0x0c287fff8030: 00 00 00 00 00 00 00 00 00 00[fa]fa fa fa fa fa
      0x0c287fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0c287fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0c287fff8060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0c287fff8070: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      0x0c287fff8080: 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
    ==253933==ABORTING
    
    

    堆栈缓冲区溢出 stack-buffer-overflow

    g++ main.cpp -o main -fsanitize=address -g -fno-omit-frame-pointer
    

    main.cpp

    int main(int argc, char **argv) {
        int stack_array[100];
        stack_array[1] = 0;
        return stack_array[argc + 100];  // BOOM
    }
    
    $./main
    =================================================================
    ==254014==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fffe071bd14 at pc 0x55a0f99743f4 bp 0x7fffe071bb30 sp 0x7fffe071bb20
    READ of size 4 at 0x7fffe071bd14 thread T0
        #0 0x55a0f99743f3 in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:6
        #1 0x7fd9ce1cb082 in __libc_start_main ../csu/libc-start.c:308
        #2 0x55a0f99741ed in _start (/home/fukaiqiang/src/code/CPLUS_HASHMAP/main+0x11ed)
    
    Address 0x7fffe071bd14 is located in stack of thread T0 at offset 452 in frame
        #0 0x55a0f99742b8 in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:3
    
      This frame has 1 object(s):
        [48, 448) 'stack_array' (line 4) <== Memory access at offset 452 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/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:6 in main
    Shadow bytes around the buggy address:
      0x10007c0db750: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x10007c0db760: 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1 f1 f1
      0x10007c0db770: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x10007c0db780: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x10007c0db790: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    =>0x10007c0db7a0: 00 00[f3]f3 f3 f3 f3 f3 f3 f3 00 00 00 00 00 00
      0x10007c0db7b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x10007c0db7c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x10007c0db7d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x10007c0db7e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x10007c0db7f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    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
    ==254014==ABORTING
    
    

    全局缓冲区溢出 global-buffer-overflow

    g++ main.cpp -o main -fsanitize=address -g -fno-omit-frame-pointer
    

    main.cpp

    int global_array[100] = {-1};
    int main(int argc, char **argv) {
      return global_array[argc + 100];  // BOOM
    }
    
    $./main
    =================================================================
    ==254097==ERROR: AddressSanitizer: global-buffer-overflow on address 0x555eb65421b4 at pc 0x555eb653f2ab bp 0x7ffd3c1e5500 sp 0x7ffd3c1e54f0
    READ of size 4 at 0x555eb65421b4 thread T0
        #0 0x555eb653f2aa in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:7
        #1 0x7eff22dcb082 in __libc_start_main ../csu/libc-start.c:308
        #2 0x555eb653f18d in _start (/home/fukaiqiang/src/code/CPLUS_HASHMAP/main+0x118d)
    
    0x555eb65421b4 is located 4 bytes to the right of global variable 'global_array' defined in 'main.cpp:5:5' (0x555eb6542020) of size 400
    SUMMARY: AddressSanitizer: global-buffer-overflow /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:7 in main
    Shadow bytes around the buggy address:
      0x0aac56ca03e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0aac56ca03f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0aac56ca0400: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0aac56ca0410: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0aac56ca0420: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    =>0x0aac56ca0430: 00 00 00 00 00 00[f9]f9 f9 f9 f9 f9 00 00 00 00
      0x0aac56ca0440: 00 00 00 00 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
      0x0aac56ca0450: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 00 00 00 00
      0x0aac56ca0460: 01 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 00 00 00 00
      0x0aac56ca0470: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0aac56ca0480: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    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
    ==254097==ABORTING
    
    

    return后使用 stack-use-after-return

    g++ main.cpp -o main -fsanitize=address -g -fno-omit-frame-pointer
    

    main.cpp

    int *ptr;
    __attribute__((noinline))
    void FunctionThatEscapesLocalObject() {
      int local[100];
      ptr = &local[0];
    }
    
    int main(int argc, char **argv) {
      FunctionThatEscapesLocalObject();
      return ptr[argc];
    }
    
    $./main
    =================================================================
    ==254255==ERROR: AddressSanitizer: stack-use-after-return on address 0x7f514b54e034 at pc 0x55ee93d46432 bp 0x7ffedaba1700 sp 0x7ffedaba16f0
    READ of size 4 at 0x7f514b54e034 thread T0
        #0 0x55ee93d46431 in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:13
        #1 0x7f514e90b082 in __libc_start_main ../csu/libc-start.c:308
        #2 0x55ee93d461cd in _start (/home/fukaiqiang/src/code/CPLUS_HASHMAP/main+0x11cd)
    
    Address 0x7f514b54e034 is located in stack of thread T0 at offset 52 in frame
        #0 0x55ee93d46298 in FunctionThatEscapesLocalObject() /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:6
    
      This frame has 1 object(s):
        [48, 448) 'local' (line 7) <== Memory access at offset 52 is inside 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-use-after-return /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:13 in main
    Shadow bytes around the buggy address:
      0x0feaa96a1bb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0feaa96a1bc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0feaa96a1bd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0feaa96a1be0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0feaa96a1bf0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    =>0x0feaa96a1c00: f5 f5 f5 f5 f5 f5[f5]f5 f5 f5 f5 f5 f5 f5 f5 f5
      0x0feaa96a1c10: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
      0x0feaa96a1c20: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
      0x0feaa96a1c30: f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5 f5
      0x0feaa96a1c40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0feaa96a1c50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    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
    ==254255==ABORTING
    
    

    模块外使用 stack-use-after-scope

    g++ main.cpp -o main -fsanitize=address -g -fno-omit-frame-pointer
    

    main.cpp

    volatile int *p = 0;
    
    int main() {
        {
            int x = 0;
            p = &x;
        }
        *p = 5;
        return 0;
    }
    
    $./main
    =================================================================
    ==257062==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7f59030dc020 at pc 0x564bb2fb83a1 bp 0x7ffe4bc65f70 sp 0x7ffe4bc65f60
    WRITE of size 4 at 0x7f59030dc020 thread T0
        #0 0x564bb2fb83a0 in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:10
        #1 0x7f5906799082 in __libc_start_main ../csu/libc-start.c:308
        #2 0x564bb2fb81cd in _start (/home/fukaiqiang/src/code/CPLUS_HASHMAP/main+0x11cd)
    
    Address 0x7f59030dc020 is located in stack of thread T0 at offset 32 in frame
        #0 0x564bb2fb8298 in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:5
    
      This frame has 1 object(s):
        [32, 36) 'x' (line 7) <== Memory access at offset 32 is inside 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-use-after-scope /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:10 in main
    Shadow bytes around the buggy address:
      0x0feba06137b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0feba06137c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0feba06137d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0feba06137e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0feba06137f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    =>0x0feba0613800: f1 f1 f1 f1[f8]f3 f3 f3 00 00 00 00 00 00 00 00
      0x0feba0613810: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0feba0613820: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0feba0613830: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0feba0613840: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0feba0613850: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    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
    ==257062==ABORTING
    
    

    detected memory leaks

    g++ main.cpp -o main -fsanitize=address -g -fno-omit-frame-pointer
    

    main.cpp

    #include <iostream>
    
    void *p;
    
    int main() {
        p = malloc(7);
        p = 0; // The memory is leaked here.
        return 0;
    }
    
    $./main
    
    =================================================================
    ==257159==ERROR: LeakSanitizer: detected memory leaks
    
    Direct leak of 7 byte(s) in 1 object(s) allocated from:
        #0 0x7fc06e071808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
        #1 0x555b0c6d825a in main /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:6
        #2 0x7fc06da4a082 in __libc_start_main ../csu/libc-start.c:308
    
    SUMMARY: AddressSanitizer: 7 byte(s) leaked in 1 allocation(s).
    

    初始化问题 Initialization order bugs

    g++ test.cpp main.cpp -o main -fsanitize=address -g -fno-omit-frame-pointer
    

    test.cpp

    int foo() { return 42; }
    int extern_global = foo();
    

    main.cpp

    #include <iostream>
    
    extern int extern_global;
    int __attribute__((noinline)) read_extern_global() {
        return extern_global;
    }
    int x = read_extern_global() + 1;
    int main() {
        printf("%d\n", x);
        return 0;
    }
    
    $./main
    =================================================================
    ==264374==ERROR: AddressSanitizer: initialization-order-fiasco on address 0x55e2925711e0 at pc 0x55e29256e3a8 bp 0x7ffd807a1ba0 sp 0x7ffd807a1b90
    READ of size 4 at 0x55e2925711e0 thread T0
        #0 0x55e29256e3a7 in read_extern_global() /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:5
        #1 0x55e29256e468 in __static_initialization_and_destruction_0 /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:7
        #2 0x55e29256e4c3 in _GLOBAL__sub_I__Z18read_extern_globalv /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:11
        #3 0x55e29256e55c in __libc_csu_init (/home/fukaiqiang/src/code/CPLUS_HASHMAP/main+0x155c)
        #4 0x7fb3e7e8400f in __libc_start_main ../csu/libc-start.c:264
        #5 0x55e29256e1cd in _start (/home/fukaiqiang/src/code/CPLUS_HASHMAP/main+0x11cd)
    
    0x55e2925711e0 is located 0 bytes inside of global variable 'extern_global' defined in 'test.cpp:6:5' (0x55e2925711e0) of size 4
      registered at:
        #0 0x7fb3e83d59bf in __asan_register_globals ../../../../src/libsanitizer/asan/asan_globals.cc:342
        #1 0x55e29256e363 in _sub_I_00099_1 (/home/fukaiqiang/src/code/CPLUS_HASHMAP/main+0x1363)
        #2 0x55e29256e55c in __libc_csu_init (/home/fukaiqiang/src/code/CPLUS_HASHMAP/main+0x155c)
    
    SUMMARY: AddressSanitizer: initialization-order-fiasco /home/fukaiqiang/src/code/CPLUS_HASHMAP/main.cpp:5 in read_extern_global()
    Shadow bytes around the buggy address:
      0x0abcd24a61e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0abcd24a61f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0abcd24a6200: 00 00 00 00 00 00 00 00 f9 f9 f9 f9 f9 f9 f9 f9
      0x0abcd24a6210: 00 00 00 00 00 00 00 00 f9 f9 f9 f9 f9 f9 f9 f9
      0x0abcd24a6220: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
    =>0x0abcd24a6230: f9 f9 f9 f9 f9 f9 f9 f9 00 00 00 00[f6]f6 f6 f6
      0x0abcd24a6240: f6 f6 f6 f6 00 00 00 00 01 f9 f9 f9 f9 f9 f9 f9
      0x0abcd24a6250: 04 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 00 00 00 00
      0x0abcd24a6260: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0abcd24a6270: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      0x0abcd24a6280: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    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
    ==264374==ABORTING
    

    参考

    https://github.com/google/sanitizers/wiki/AddressSanitizer

    相关文章

      网友评论

          本文标题:AddressSanitizer 简介和示例

          本文链接:https://www.haomeiwen.com/subject/ftnpcjtx.html