Stack-based buffer overflow in the to_comma() function
ATasm is a 6502 command-line cross-assembler.
Brought to you by:
schmelze
Hi,
While fuzzing ATasm 1.08 with Honggfuzz, I found a stack-based buffer overflow in the to_comma() function, in asm.c.
Attaching a reproducer, issue can be reproduced by running:
atasm test01
=================================================================
==15033==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffec9190ef0 at pc 0x0000004ce38e bp 0x7ffec9190e30 sp 0x7ffec9190e28
WRITE of size 1 at 0x7ffec9190ef0 thread T0
#0 0x4ce38d in to_comma /home/fcambus/atasm/src/asm.c:1126:11
#1 0x4ce38d in do_xbyte /home/fcambus/atasm/src/asm.c:1346:9
#2 0x4cfe17 in proc_sym /home/fcambus/atasm/src/asm.c:1553:7
#3 0x4d5556 in do_cmd /home/fcambus/atasm/src/asm.c:1941:5
#4 0x4d5b46 in assemble /home/fcambus/atasm/src/asm.c:1980:9
#5 0x4d8082 in main /home/fcambus/atasm/src/asm.c:2392:3
#6 0x7f32f46441e2 in __libc_start_main /build/glibc-4WA41p/glibc-2.30/csu/../csu/libc-start.c:308:16
#7 0x41b3fd in _start (/home/fcambus/atasm/atasm+0x41b3fd)
Address 0x7ffec9190ef0 is located in stack of thread T0 at offset 176 in frame
#0 0x4cc7af in do_xbyte /home/fcambus/atasm/src/asm.c:1299
This frame has 2 object(s):
[32, 64) 'buf.i' (line 736)
[96, 176) 'buf' (line 1301) <== Memory access at offset 176 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/fcambus/atasm/src/asm.c:1126:11 in to_comma
Shadow bytes around the buggy address:
0x10005922a180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10005922a190: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10005922a1a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10005922a1b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10005922a1c0: 00 00 00 00 00 00 00 00 f1 f1 f1 f1 f8 f8 f8 f8
=>0x10005922a1d0: f2 f2 f2 f2 00 00 00 00 00 00 00 00 00 00[f3]f3
0x10005922a1e0: f3 f3 f3 f3 00 00 00 00 00 00 00 00 00 00 00 00
0x10005922a1f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10005922a200: 00 00 00 00 00 00 00 00 f1 f1 f1 f1 f8 f8 f8 f8
0x10005922a210: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8
0x10005922a220: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f2 f2 f2 f2
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
==15033==ABORTING
This issue has been assigned CVE-2019-19785.
Fixed in Version 1.9 https://github.com/CycoPH/atasm