foxygit / doom Log in
commit 5e51c2032749df58fadc8182da345acb18b19885
Author:     Simon Howard <fraggle@soulsphere.org>
AuthorDate: Fri Jan 5 12:41:32 2018 +0100
Commit:     Simon Howard <fraggle@soulsphere.org>
CommitDate: Fri Jan 5 12:41:32 2018 +0100

    hexen: Add bounds checking for CmdPrintCharacter.

    If adding another character to the print buffer would cause a buffer
    overflow, don't exceed the limits of the buffer. Similar protection
    is already in place for CmdPrintString and CmdPrintNumber.
---
 src/hexen/p_acs.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/hexen/p_acs.c b/src/hexen/p_acs.c
index f0cf190b..16725b74 100644
--- a/src/hexen/p_acs.c
+++ b/src/hexen/p_acs.c
@@ -1817,11 +1817,12 @@ static int CmdPrintNumber(void)

 static int CmdPrintCharacter(void)
 {
-    char *bufferEnd;
+    char tempStr[2];
+
+    tempStr[0] = Pop();
+    tempStr[1] = '\0';
+    M_StringConcat(PrintBuffer, tempStr, sizeof(PrintBuffer));

-    bufferEnd = PrintBuffer + strlen(PrintBuffer);
-    *bufferEnd++ = Pop();
-    *bufferEnd = 0;
     return SCRIPT_CONTINUE;
 }