From 37101f826eca9138447042987c0b06172fa9bc36 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Mon, 14 Oct 2019 22:12:26 -0400 Subject: [PATCH 1/2] Allow access to players userdata outside levels. In exchange for preventing access to any mobj_t userdata outside levels, including player's own mobj_t. --- src/lua_mobjlib.c | 2 ++ src/lua_playerlib.c | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 063158b26..2cb9dc329 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -160,6 +160,7 @@ static const char *const mobj_opt[] = { static int mobj_get(lua_State *L) { + INLEVEL mobj_t *mo = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); enum mobj_e field = Lua_optoption(L, 2, NULL, mobj_opt); lua_settop(L, 2); @@ -405,6 +406,7 @@ static int mobj_get(lua_State *L) #define NOSETPOS luaL_error(L, LUA_QL("mobj_t") " field " LUA_QS " should not be set directly. Use " LUA_QL("P_Move") ", " LUA_QL("P_TryMove") ", or " LUA_QL("P_TeleportMove") " instead.", mobj_opt[field]) static int mobj_set(lua_State *L) { + INLEVEL mobj_t *mo = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); enum mobj_e field = Lua_optoption(L, 2, mobj_opt[0], mobj_opt); lua_settop(L, 3); diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c index dd9959afb..b1222ce67 100644 --- a/src/lua_playerlib.c +++ b/src/lua_playerlib.c @@ -25,7 +25,6 @@ static int lib_iteratePlayers(lua_State *L) { INT32 i = -1; - INLEVEL if (lua_gettop(L) < 2) { //return luaL_error(L, "Don't call players.iterate() directly, use it as 'for player in players.iterate do end'."); @@ -52,7 +51,6 @@ static int lib_getPlayer(lua_State *L) { const char *field; // i -> players[i] - INLEVEL if (lua_type(L, 2) == LUA_TNUMBER) { lua_Integer i = luaL_checkinteger(L, 2); From 630bdaa876991d1aecab8de59f3b706335d3d463 Mon Sep 17 00:00:00 2001 From: toaster Date: Thu, 24 Oct 2019 21:14:51 +0100 Subject: [PATCH 2/2] Move INLEVEL macros for mobj_get and mobj_set to prevent mixed code/declaration errors. --- src/lua_mobjlib.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 2cb9dc329..30026da49 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -160,11 +160,12 @@ static const char *const mobj_opt[] = { static int mobj_get(lua_State *L) { - INLEVEL mobj_t *mo = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); enum mobj_e field = Lua_optoption(L, 2, NULL, mobj_opt); lua_settop(L, 2); + INLEVEL + if (!mo) { if (field == mobj_valid) { lua_pushboolean(L, 0); @@ -406,11 +407,12 @@ static int mobj_get(lua_State *L) #define NOSETPOS luaL_error(L, LUA_QL("mobj_t") " field " LUA_QS " should not be set directly. Use " LUA_QL("P_Move") ", " LUA_QL("P_TryMove") ", or " LUA_QL("P_TeleportMove") " instead.", mobj_opt[field]) static int mobj_set(lua_State *L) { - INLEVEL mobj_t *mo = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); enum mobj_e field = Lua_optoption(L, 2, mobj_opt[0], mobj_opt); lua_settop(L, 3); + INLEVEL + if (!mo) return LUA_ErrInvalid(L, "mobj_t");