shithub: choc

Download patch

ref: 7a0db31614ec187e363e7664036d95ec56242e44
parent: 7dce8d5c99ddcb2a0dd8d12cd1ea86e5a6523f63
author: Alexandre-Xavier Labonté-Lamoureux <alexandrexavier@live.ca>
date: Tue Oct 6 22:46:37 EDT 2020

textscreen: Fix SetBufferFromValue to copy the right amount of data (#1321)

Fix the amount of data that must be copied from the value pointer to the inputbox buffer. This fixes a bug with ASCII where the last character would be deleted if the inputbox is completely filled up. This also fixes a bug where UTF8 input would be truncated. Truncating UTF8 data could lead to a buffer overflow.

--- a/textscreen/txt_inputbox.c
+++ b/textscreen/txt_inputbox.c
@@ -37,7 +37,7 @@
 
         if (*value != NULL)
         {
-            TXT_StringCopy(inputbox->buffer, *value, inputbox->size);
+            TXT_StringCopy(inputbox->buffer, *value, strnlen(*value, inputbox->buffer_len) + 1);
         }
         else
         {