AddressSanitizer 简介和示例

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

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 206,602评论 6 481
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,442评论 2 382
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 152,878评论 0 344
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,306评论 1 279
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,330评论 5 373
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,071评论 1 285
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,382评论 3 400
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,006评论 0 259
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,512评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,965评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,094评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,732评论 4 323
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,283评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,286评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,512评论 1 262
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,536评论 2 354
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,828评论 2 345

推荐阅读更多精彩内容