Skip to content

Commit 548a1a3

Browse files
committed
Enable safe Os functions
1 parent 8b01d7b commit 548a1a3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ void CLuaMain::ResetInstructionCount(void)
7373

7474
void CLuaMain::InitSecurity(void)
7575
{
76+
// 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);
91+
7692
lua_register(m_luaVM, "dofile", CLuaUtilDefs::DisabledFunction);
7793
lua_register(m_luaVM, "loadfile", CLuaUtilDefs::DisabledFunction);
7894
lua_register(m_luaVM, "require", CLuaUtilDefs::DisabledFunction);
@@ -141,6 +157,7 @@ void CLuaMain::InitVM(void)
141157
luaopen_table(m_luaVM);
142158
luaopen_debug(m_luaVM);
143159
luaopen_utf8(m_luaVM);
160+
luaopen_os(m_luaVM);
144161

145162
// Initialize security restrictions. Very important to prevent lua trojans and viruses!
146163
InitSecurity();

0 commit comments

Comments
 (0)