Tested Asan test as follows with command "runqemu nographic"
(with IMAGE_INSTALL:append = " libasan libasan-dev"):
root@qemuriscv64:~# gcc -g -fsanitize=address -o asan_test asan_test.c
root@qemuriscv64:~# ./asan_test
Running AddressSanitizer test...
=================================================================
==262==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x003f9380002a at pc 0x002add509b88 bp 0x003ff6510ec0 sp 0x003ff6510e90
WRITE of size 1 at 0x003f9380002a thread T0
#0 0x2add509b86 in cause_buffer_overflow /home/root/a.c:9
#1 0x2add509ca2 in main /home/root/a.c:16
#2 0x3f95a917b4 (/lib/libc.so.6+0x277b4) (BuildId: 89440b2a8f8e9f78366a816e4685a39d6a4de4c5)
#3 0x3f95a9185c in __libc_start_main (/lib/libc.so.6+0x2785c) (BuildId: 89440b2a8f8e9f78366a816e4685a39d6a4de4c5)
#4 0x2add509a1e in _start ../sysdeps/riscv/start.S:67
Address 0x003f9380002a is located in stack of thread T0 at offset 42 in frame
#0 0x2add509ac4 in cause_buffer_overflow /home/root/a.c:5
This frame has 1 object(s):
[32, 42) 'buffer' (line 6) <== Memory access at offset 42 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/root/a.c:9 in cause_buffer_overflow
Shadow bytes around the buggy address:
0x003f937ffd80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x003f937ffe00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x003f937ffe80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x003f937fff00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x003f937fff80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x003f93800000: f1 f1 f1 f1 00[02]f3 f3 00 00 00 00 00 00 00 00
0x003f93800080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x003f93800100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x003f93800180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x003f93800200: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x003f93800280: 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