Brandy Basic V Interpreter Bugs
Brandy is an interpreter for BBC Basic
Brought to you by:
dave_daniels
Hi,
While fuzzing Brandy with American Fuzzy Lop, I found a stack-based buffer overflow in the fileio_openout() function, in src/fileio.c L502.
Attaching a reproducer, issue can be reproduced by running:
brandy test02
=================================================================
==20881==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffdd1ea3f80 at pc 0x7ff66845bd82 bp 0x7ffdd1ea3e30 sp 0x7ffdd1ea35d8
WRITE of size 445 at 0x7ffdd1ea3f80 thread T0
#0 0x7ff66845bd81 in __interceptor_memmove (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x7ad81)
#1 0x55b764d0a277 in fileio_openout src/fileio.c:502
#2 0x55b764d05d99 in fn_openout src/functions.c:1063
#3 0x55b764d09ba3 in exec_function src/functions.c:1777
#4 0x55b764d24a8e in expression src/evaluate.c:3495
#5 0x55b764cfdd20 in print_screen src/iostate.c:1428
#6 0x55b764cfe8bb in exec_print src/iostate.c:1532
#7 0x55b764cd0b35 in exec_statements src/statement.c:397
#8 0x55b764cd0ead in run_program src/statement.c:436
#9 0x55b764d32e9e in run_interpreter src/brandy.c:326
#10 0x55b764d31f6c in main src/brandy.c:71
#11 0x7ff667c73b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#12 0x55b764cbd799 in _start (/home/fcambus/brandy-openout/tbrandy+0x1d799)
Address 0x7ffdd1ea3f80 is located in stack of thread T0 at offset 288 in frame
#0 0x55b764d0a132 in fileio_openout src/fileio.c:496
This frame has 1 object(s):
[32, 288) 'filename' <== Memory access at offset 288 overflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x7ad81) in __interceptor_memmove
Shadow bytes around the buggy address:
0x10003a3cc7a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10003a3cc7b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10003a3cc7c0: 00 00 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1
0x10003a3cc7d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10003a3cc7e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x10003a3cc7f0:[f3]f3 f3 f3 00 00 00 00 00 00 00 00 00 00 00 00
0x10003a3cc800: f1 f1 f1 f1 00 00 f2 f2 f3 f3 f3 f3 00 00 00 00
0x10003a3cc810: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10003a3cc820: f1 f1 f1 f1 00 00 f2 f2 f3 f3 f3 f3 00 00 00 00
0x10003a3cc830: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10003a3cc840: 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
==20881==ABORTING
This issue has been assigned CVE-2019-14662.
Fixed downstream on the Matrix Brandy fork.