Skip to content

Commit 944c01b

Browse files
committed
Set disabled Os functions to CLuaUtilDefs::DisabledFunction
1 parent 6322826 commit 944c01b

File tree

2 files changed

+22
-28
lines changed

2 files changed

+22
-28
lines changed

Client/mods/deathmatch/logic/lua/CLuaMain.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,17 @@ void CLuaMain::ResetInstructionCount(void)
7474
void CLuaMain::InitSecurity(void)
7575
{
7676
// Disable dangerous Lua Os library functions
77-
lua_getglobal(m_luaVM, "os");
78-
lua_pushnil(m_luaVM);
79-
lua_setfield(m_luaVM, -2, "execute");
80-
lua_pushnil(m_luaVM);
81-
lua_setfield(m_luaVM, -2, "rename");
82-
lua_pushnil(m_luaVM);
83-
lua_setfield(m_luaVM, -2, "remove");
84-
lua_pushnil(m_luaVM);
85-
lua_setfield(m_luaVM, -2, "exit");
86-
lua_pushnil(m_luaVM);
87-
lua_setfield(m_luaVM, -2, "getenv");
88-
lua_pushnil(m_luaVM);
89-
lua_setfield(m_luaVM, -2, "tmpname");
90-
lua_pop(m_luaVM, 1);
77+
static const luaL_reg osfuncs[] =
78+
{
79+
{ "execute", CLuaUtilDefs::DisabledFunction },
80+
{ "rename", CLuaUtilDefs::DisabledFunction },
81+
{ "remove", CLuaUtilDefs::DisabledFunction },
82+
{ "exit", CLuaUtilDefs::DisabledFunction },
83+
{ "getenv", CLuaUtilDefs::DisabledFunction },
84+
{ "tmpname", CLuaUtilDefs::DisabledFunction },
85+
{ NULL, NULL }
86+
};
87+
luaL_register(m_luaVM, "os", osfuncs);
9188

9289
lua_register(m_luaVM, "dofile", CLuaUtilDefs::DisabledFunction);
9390
lua_register(m_luaVM, "loadfile", CLuaUtilDefs::DisabledFunction);

Server/mods/deathmatch/logic/lua/CLuaMain.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,17 @@ void CLuaMain::ResetInstructionCount(void)
109109
void CLuaMain::InitSecurity(void)
110110
{
111111
// Disable dangerous Lua Os library functions
112-
lua_getglobal(m_luaVM, "os");
113-
lua_pushnil(m_luaVM);
114-
lua_setfield(m_luaVM, -2, "execute");
115-
lua_pushnil(m_luaVM);
116-
lua_setfield(m_luaVM, -2, "rename");
117-
lua_pushnil(m_luaVM);
118-
lua_setfield(m_luaVM, -2, "remove");
119-
lua_pushnil(m_luaVM);
120-
lua_setfield(m_luaVM, -2, "exit");
121-
lua_pushnil(m_luaVM);
122-
lua_setfield(m_luaVM, -2, "getenv");
123-
lua_pushnil(m_luaVM);
124-
lua_setfield(m_luaVM, -2, "tmpname");
125-
lua_pop(m_luaVM, 1);
112+
static const luaL_reg osfuncs[] =
113+
{
114+
{ "execute", CLuaUtilDefs::DisabledFunction },
115+
{ "rename", CLuaUtilDefs::DisabledFunction },
116+
{ "remove", CLuaUtilDefs::DisabledFunction },
117+
{ "exit", CLuaUtilDefs::DisabledFunction },
118+
{ "getenv", CLuaUtilDefs::DisabledFunction },
119+
{ "tmpname", CLuaUtilDefs::DisabledFunction },
120+
{ NULL, NULL }
121+
};
122+
luaL_register(m_luaVM, "os", osfuncs);
126123

127124
lua_register(m_luaVM, "dofile", CLuaUtilDefs::DisabledFunction);
128125
lua_register(m_luaVM, "loadfile", CLuaUtilDefs::DisabledFunction);

0 commit comments

Comments
 (0)