OPENWRITE checks list length before attempting to access buffer size
SETWRITE checks list length before attempting to access buffer size
When writing to a buffer, allocate one extra byte for null terminator
Zero out allocated buffer to prevent left over data from appearing
Details
The original bug stated that SETWRITE [WORD] causes a crash. The root cause was SETWRITE assuming a list parameter would have two items and not checking before dereferencing the second item. This crash condition also appeared in OPENWRITE [WORD].
While testing those two fixes, I noticed that, if the data written in Logo is longer than the buffer, it is not properly NULL terminated on the C side of things. The following snippet fairly reliably demonstrates the issue:
MAKE "char.buffer [buffer 10]
REPEAT 10 [
OPENWRITE :char.buffer
SETWRITE :char.buffer
TYPE "0123456789ABCDEF
CLOSE :char.buffer
PRINT :buffer
]
The last issue is that allocating a buffer of 10 in Logo gives 9 writeable characters (since the 10th is reserved for a NULL terminator on the C side). I tweaked the code to allocate one extra space for the NULL character so that this detail isn't exposed on the Logo side of things.
Test Environments
OSX Catalina 10.15.7 w/ wxWidgets 3.0.5
Ubuntu Bionic (18.04.5) w/ wxWidgets 3.0.5
Windows 10 Home (1909) w/ wxWidgets 3.0.5
Resolves #51
Summary
OPENWRITE
checks list length before attempting to access buffer sizeSETWRITE
checks list length before attempting to access buffer sizeDetails
The original bug stated that
SETWRITE [WORD]
causes a crash. The root cause wasSETWRITE
assuming a list parameter would have two items and not checking before dereferencing the second item. This crash condition also appeared inOPENWRITE [WORD]
.While testing those two fixes, I noticed that, if the data written in Logo is longer than the buffer, it is not properly
NULL
terminated on the C side of things. The following snippet fairly reliably demonstrates the issue:Yielding:
The last issue is that allocating a buffer of 10 in Logo gives 9 writeable characters (since the 10th is reserved for a
NULL
terminator on the C side). I tweaked the code to allocate one extra space for theNULL
character so that this detail isn't exposed on the Logo side of things.Test Environments
OSX Catalina 10.15.7 w/ wxWidgets 3.0.5 Ubuntu Bionic (18.04.5) w/ wxWidgets 3.0.5 Windows 10 Home (1909) w/ wxWidgets 3.0.5