From 8cf064b90cc478d52aa780ab62dfc8964028e40b Mon Sep 17 00:00:00 2001 From: "Richard C. Gobeille" Date: Wed, 6 May 2020 04:40:05 -0700 Subject: [PATCH] Duke3d: add a few missing VM_ASSERT checks --- source/duke3d/src/gameexec.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/source/duke3d/src/gameexec.cpp b/source/duke3d/src/gameexec.cpp index cd28e8742..11cd1346a 100644 --- a/source/duke3d/src/gameexec.cpp +++ b/source/duke3d/src/gameexec.cpp @@ -2384,6 +2384,8 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/) int const labelNum = *insptr++; int const lParm2 = (PlayerLabels[labelNum].flags & LABEL_HASPARM2) ? Gv_GetVar(*insptr++) : 0; + VM_ASSERT((unsigned)playerNum < MAXPLAYERS, "invalid player %d\n", playerNum); + VM_SetPlayer(playerNum, labelNum, lParm2, Gv_GetVar(*insptr++)); dispatch(); } @@ -2395,6 +2397,8 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/) int const labelNum = *insptr++; int const lParm2 = (PlayerLabels[labelNum].flags & LABEL_HASPARM2) ? Gv_GetVar(*insptr++) : 0; + VM_ASSERT((unsigned)playerNum < MAXPLAYERS, "invalid player %d\n", playerNum); + Gv_SetVar(*insptr++, VM_GetPlayer(playerNum, labelNum, lParm2)); dispatch(); } @@ -2408,6 +2412,8 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/) int const newValue = Gv_GetVar(*insptr++); auto const &wallLabel = WallLabels[labelNum]; + VM_ASSERT((unsigned)wallNum < MAXWALLS, "invalid wall %d\n", wallNum); + if (wallLabel.offset == -1 || wallLabel.flags & LABEL_WRITEFUNC) { VM_SetWall(wallNum, labelNum, newValue); @@ -2428,6 +2434,8 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/) int const labelNum = *insptr++; auto const &wallLabel = WallLabels[labelNum]; + VM_ASSERT((unsigned)wallNum < MAXWALLS, "invalid wall %d\n", wallNum); + Gv_SetVar(*insptr++, (wallLabel.offset != -1 && (wallLabel.flags & LABEL_READFUNC) != LABEL_READFUNC) ? VM_GetStruct(wallLabel.flags, (intptr_t *)((char *)&wall[wallNum] + wallLabel.offset)) @@ -2594,6 +2602,8 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/) int const labelNum = *insptr++; auto const &tsprLabel = TsprLabels[labelNum]; + VM_ASSERT((unsigned)spriteNum < MAXSPRITES, "invalid sprite %d\n", spriteNum); + VM_SetStruct(tsprLabel.flags, (intptr_t *)((char *)spriteext[spriteNum].tspr + tsprLabel.offset), Gv_GetVar(*insptr++)); dispatch(); } @@ -2605,6 +2615,8 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/) int const labelNum = *insptr++; auto const &tsprLabel = TsprLabels[labelNum]; + VM_ASSERT((unsigned)spriteNum < MAXSPRITES, "invalid sprite %d\n", spriteNum); + Gv_SetVar(*insptr++, VM_GetStruct(tsprLabel.flags, (intptr_t *)((char *)spriteext[spriteNum].tspr + tsprLabel.offset))); dispatch(); } @@ -2617,6 +2629,8 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/) auto const §Label = SectorLabels[labelNum]; int const newValue = Gv_GetVar(*insptr++); + VM_ASSERT((unsigned)sectNum < MAXSECTORS, "invalid sector %d\n", sectNum); + if (sectLabel.offset == -1 || sectLabel.flags & LABEL_WRITEFUNC) { VM_SetSector(sectNum, labelNum, newValue); @@ -2634,6 +2648,8 @@ GAMEEXEC_STATIC void VM_Execute(int const loop /*= false*/) int const labelNum = *insptr++; auto const §Label = SectorLabels[labelNum]; + VM_ASSERT((unsigned)sectNum < MAXSECTORS, "invalid sector %d\n", sectNum); + Gv_SetVar(*insptr++, (sectLabel.offset != -1 && (sectLabel.flags & LABEL_READFUNC) != LABEL_READFUNC) ? VM_GetStruct(sectLabel.flags, (intptr_t *)((char *)§or[sectNum] + sectLabel.offset))