From 295d9768ced3907f127ffb034fa3d7d2094c34b9 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 16 Jul 2024 16:42:26 +0300 Subject: [PATCH] Fix linedef 415 executing random text if script lump doesn't have null terminator --- src/p_spec.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/p_spec.c b/src/p_spec.c index e72cb5371..91f3b5bab 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2610,7 +2610,17 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) CONS_Debug(DBG_SETUP, "SOC Error: script lump %s not found/not valid.\n", newname); } else - COM_BufInsertText(W_CacheLumpNum(lumpnum, PU_CACHE)); + { + // W_CacheLumpNum may not have null terminator, so we need to do this :blobcatgooglyholditsheadinitshands: + size_t len = W_LumpLength(lumpnum); + char *script = Z_Malloc(len+1, PU_STATIC, NULL); + memcpy(script, W_CacheLumpNum(lumpnum, PU_CACHE), len); + script[len] = 0; + + COM_BufInsertText(script); + + Z_Free(script); + } } break;