Got_Luacmd: ensure lua stack is large enough for command arguments

This commit is contained in:
James R 2024-02-11 05:33:20 -08:00
parent da84a94362
commit 42bca87c9a

View file

@ -30,6 +30,12 @@ return luaL_error(L, "HUD rendering code should not call this function!");
static consvar_t *this_cvar; static consvar_t *this_cvar;
static void clear_lua_stack(void)
{
if (gL) // check if Lua is actually turned on first, you dummmy -- Monster Iestyn 04/07/18
lua_settop(gL, 0); // clear stack
}
void Got_Luacmd(UINT8 **cp, INT32 playernum) void Got_Luacmd(UINT8 **cp, INT32 playernum)
{ {
UINT8 i, argc, flags; UINT8 i, argc, flags;
@ -74,6 +80,13 @@ void Got_Luacmd(UINT8 **cp, INT32 playernum)
lua_remove(gL, -2); // pop command info table lua_remove(gL, -2); // pop command info table
if (!lua_checkstack(gL, argc)) // player + command arguments
{
clear_lua_stack();
CONS_Alert(CONS_WARNING, "lua command stack overflow from %s (%d, need %d more)\n", player_names[playernum], lua_gettop(gL), argc);
return;
}
LUA_PushUserdata(gL, &players[playernum], META_PLAYER); LUA_PushUserdata(gL, &players[playernum], META_PLAYER);
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
{ {
@ -85,8 +98,7 @@ void Got_Luacmd(UINT8 **cp, INT32 playernum)
deny: deny:
//must be hacked/buggy client //must be hacked/buggy client
if (gL) // check if Lua is actually turned on first, you dummmy -- Monster Iestyn 04/07/18 clear_lua_stack();
lua_settop(gL, 0); // clear stack
CONS_Alert(CONS_WARNING, M_GetText("Illegal lua command received from %s\n"), player_names[playernum]); CONS_Alert(CONS_WARNING, M_GetText("Illegal lua command received from %s\n"), player_names[playernum]);
if (server) if (server)