ref: 118d869f5b104563284ac033e156a6bb85a4d642
parent: 005a79c6528d7b98c37f24e548e805f6435f0e36
author: Simon Howard <[email protected]>
date: Thu Jan 4 20:27:11 EST 2018
hexen: Add bounds checking for world variables. There is a fixed number of world variables and the limit should not be exceeded.
--- a/src/hexen/p_acs.c
+++ b/src/hexen/p_acs.c
@@ -900,6 +900,15 @@
return var;
}
+static int ReadWorldVar(void)
+{
+ int var = ReadCodeImmediate();
+ ACSAssert(var >= 0, "negative world variable: %d < 0", var);
+ ACSAssert(var < MAX_ACS_WORLD_VARS,
+ "invalid world variable: %d >= %d", var, MAX_ACS_WORLD_VARS);
+ return var;
+}
+
//==========================================================================
//
// P-Code Commands
@@ -1185,8 +1194,7 @@
static int CmdAssignWorldVar(void)
{
- WorldVars[LONG(*PCodePtr)] = Pop();
- ++PCodePtr;
+ WorldVars[ReadWorldVar()] = Pop();
return SCRIPT_CONTINUE;
}
@@ -1204,8 +1212,7 @@
static int CmdPushWorldVar(void)
{
- Push(WorldVars[LONG(*PCodePtr)]);
- ++PCodePtr;
+ Push(WorldVars[ReadWorldVar()]);
return SCRIPT_CONTINUE;
}
@@ -1223,8 +1230,7 @@
static int CmdAddWorldVar(void)
{
- WorldVars[LONG(*PCodePtr)] += Pop();
- ++PCodePtr;
+ WorldVars[ReadWorldVar()] += Pop();
return SCRIPT_CONTINUE;
}
@@ -1242,8 +1248,7 @@
static int CmdSubWorldVar(void)
{
- WorldVars[LONG(*PCodePtr)] -= Pop();
- ++PCodePtr;
+ WorldVars[ReadWorldVar()] -= Pop();
return SCRIPT_CONTINUE;
}
@@ -1261,8 +1266,7 @@
static int CmdMulWorldVar(void)
{
- WorldVars[LONG(*PCodePtr)] *= Pop();
- ++PCodePtr;
+ WorldVars[ReadWorldVar()] *= Pop();
return SCRIPT_CONTINUE;
}
@@ -1280,8 +1284,7 @@
static int CmdDivWorldVar(void)
{
- WorldVars[LONG(*PCodePtr)] /= Pop();
- ++PCodePtr;
+ WorldVars[ReadWorldVar()] /= Pop();
return SCRIPT_CONTINUE;
}
@@ -1299,8 +1302,7 @@
static int CmdModWorldVar(void)
{
- WorldVars[LONG(*PCodePtr)] %= Pop();
- ++PCodePtr;
+ WorldVars[ReadWorldVar()] %= Pop();
return SCRIPT_CONTINUE;
}
@@ -1318,8 +1320,7 @@
static int CmdIncWorldVar(void)
{
- ++WorldVars[LONG(*PCodePtr)];
- ++PCodePtr;
+ ++WorldVars[ReadWorldVar()];
return SCRIPT_CONTINUE;
}
@@ -1337,8 +1338,7 @@
static int CmdDecWorldVar(void)
{
- --WorldVars[LONG(*PCodePtr)];
- ++PCodePtr;
+ --WorldVars[ReadWorldVar()];
return SCRIPT_CONTINUE;
}