Skip to content

Commit 8b01d7b

Browse files
committed
Enable safe Os functions
1 parent 1321b53 commit 8b01d7b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,23 @@ void CLuaMain::InitVM(void)
172172
luaopen_table(m_luaVM);
173173
luaopen_debug(m_luaVM);
174174
luaopen_utf8(m_luaVM);
175+
luaopen_os(m_luaVM);
176+
177+
// Disable dangerous Lua Os library functions
178+
lua_getglobal(m_luaVM, "os");
179+
lua_pushnil(m_luaVM);
180+
lua_setfield(m_luaVM, -2, "execute");
181+
lua_pushnil(m_luaVM);
182+
lua_setfield(m_luaVM, -2, "rename");
183+
lua_pushnil(m_luaVM);
184+
lua_setfield(m_luaVM, -2, "remove");
185+
lua_pushnil(m_luaVM);
186+
lua_setfield(m_luaVM, -2, "exit");
187+
lua_pushnil(m_luaVM);
188+
lua_setfield(m_luaVM, -2, "getenv");
189+
lua_pushnil(m_luaVM);
190+
lua_setfield(m_luaVM, -2, "tmpname");
191+
lua_pop(m_luaVM, 1);
175192

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

0 commit comments

Comments
 (0)