Added bounds checking to gActiveMods.entries[]

This commit is contained in:
MysterD 2023-11-08 12:14:26 -08:00
parent a279154e6f
commit 03d6958a30
3 changed files with 24 additions and 0 deletions

View File

@ -1000,6 +1000,11 @@ static s32 bhv_cmd_call_native_ext(void) {
}
// Get our mod.
if (modIndex >= gActiveMods.entryCount) {
LOG_LUA("Failed to call lua function, could not find mod");
gCurBhvCommand += 2;
return BHV_PROC_CONTINUE;
}
struct Mod *mod = gActiveMods.entries[modIndex];
// Push the callback onto the stack

View File

@ -135,6 +135,11 @@ static void smlua_sync_table_call_hook(int syncTableIndex, int keyIndex, int pre
// get entry
u16 modRemoteIndex = smlua_get_integer_field(syncTableIndex, "_remoteIndex");
if (modRemoteIndex >= gActiveMods.entryCount) {
LOG_ERROR("Failed to find mod");
lua_pop(L, 4);
return;
}
struct Mod* mod = gActiveMods.entries[modRemoteIndex];
// call hook
@ -303,6 +308,10 @@ void smlua_set_sync_table_field_from_network(u64 seq, u16 modRemoteIndex, u16 ln
lua_State* L = gLuaState;
// figure out entry
if (modRemoteIndex >= gActiveMods.entryCount) {
LOG_ERROR("Could not find mod list entry for modRemoteIndex: %u", modRemoteIndex);
return;
}
struct Mod* mod = gActiveMods.entries[modRemoteIndex];
if (mod == NULL) {
LOG_ERROR("Could not find mod list entry for modRemoteIndex: %u", modRemoteIndex);

View File

@ -547,6 +547,11 @@ s64 smlua_get_integer_mod_variable(u16 modIndex, const char* variable) {
return 0;
}
if (modIndex >= gActiveMods.entryCount) {
LOG_ERROR("Could not find mod list entry");
return 0;
}
// figure out entry
struct Mod* mod = gActiveMods.entries[modIndex];
if (mod == NULL) {
@ -598,6 +603,11 @@ s64 smlua_get_any_integer_mod_variable(const char* variable) {
LuaFunction smlua_get_function_mod_variable(u16 modIndex, const char *variable) {
lua_State *L = gLuaState;
if (modIndex >= gActiveMods.entryCount) {
LOG_ERROR("Could not find mod list entry for modIndex: %u", modIndex);
return 0;
}
// figure out entry
struct Mod *mod = gActiveMods.entries[modIndex];
if (mod == NULL) {