Question
==1628787==ERROR: AddressSanitizer: heap-use-after-free on address 0x602000000015 at pc 0x56294097ae4c bp 0x7ffc6336f920 sp 0x7ffc6336f910
WRITE of size 1 at 0x602000000015 thread T0
#0 0x56294097ae4b in fat_write_certificate (/opt/workdir/prepare-to-commit/t40/smartlock/external/factory-test/fat/fat+0x4e4b)
#1 0x56294097b29e in main (/opt/workdir/prepare-to-commit/t40/smartlock/external/factory-test/fat/fat+0x529e)
#2 0x7f469339d082 in __libc_start_main ../csu/libc-start.c:308
#3 0x5629409795ed in _start (/opt/workdir/prepare-to-commit/t40/smartlock/external/factory-test/fat/fat+0x35ed)
0x602000000015 is located 5 bytes inside of 6-byte region [0x602000000010,0x602000000016)
freed by thread T0 here:
#0 0x7f4693678c3e in __interceptor_realloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:163
#1 0x56294097a551 in fat_serial_write (/opt/workdir/prepare-to-commit/t40/smartlock/external/factory-test/fat/fat+0x4551)
#2 0x56294097b27c in main (/opt/workdir/prepare-to-commit/t40/smartlock/external/factory-test/fat/fat+0x527c)
#3 0x7f469339d082 in __libc_start_main ../csu/libc-start.c:308
previously allocated by thread T0 here:
#0 0x7f4693678a06 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:153
#1 0x56294097b210 in main (/opt/workdir/prepare-to-commit/t40/smartlock/external/factory-test/fat/fat+0x5210)
#2 0x7f469339d082 in __libc_start_main ../csu/libc-start.c:308
SUMMARY: AddressSanitizer: heap-use-after-free (/opt/workdir/prepare-to-commit/t40/smartlock/external/factory-test/fat/fat+0x4e4b) in fat_write_certificate
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[fd]fa fa fa 00 04 fa fa fd 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
==1628787==ABORTING
Answer
-CFLAGS = -Wall -fsanitize=address
+CFLAGS = -Wall -fsanitize=address -g