foxygit / doom Log in
commit 7a0db31614ec187e363e7664036d95ec56242e44
Author:     Alexandre-Xavier Labonté-Lamoureux <alexandrexavier@live.ca>
AuthorDate: Wed Oct 7 02:46:37 2020 -0400
Commit:     GitHub <noreply@github.com>
CommitDate: Wed Oct 7 08:46:37 2020 +0200

    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.
---
 textscreen/txt_inputbox.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/textscreen/txt_inputbox.c b/textscreen/txt_inputbox.c
index 08054115..27a8608b 100644
--- a/textscreen/txt_inputbox.c
+++ b/textscreen/txt_inputbox.c
@@ -37,7 +37,7 @@ static void SetBufferFromValue(txt_inputbox_t *inputbox)

         if (*value != NULL)
         {
-            TXT_StringCopy(inputbox->buffer, *value, inputbox->size);
+            TXT_StringCopy(inputbox->buffer, *value, strnlen(*value, inputbox->buffer_len) + 1);
         }
         else
         {