Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable safe Lua os.* functions #316

Merged
merged 4 commits into from Sep 6, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions Server/mods/deathmatch/logic/lua/CLuaMain.cpp
Expand Up @@ -172,6 +172,23 @@ void CLuaMain::InitVM(void)
luaopen_table(m_luaVM);
luaopen_debug(m_luaVM);
luaopen_utf8(m_luaVM);
luaopen_os(m_luaVM);

// Disable dangerous Lua Os library functions
lua_getglobal(m_luaVM, "os");
lua_pushnil(m_luaVM);
lua_setfield(m_luaVM, -2, "execute");
lua_pushnil(m_luaVM);
lua_setfield(m_luaVM, -2, "rename");
lua_pushnil(m_luaVM);
lua_setfield(m_luaVM, -2, "remove");
lua_pushnil(m_luaVM);
lua_setfield(m_luaVM, -2, "exit");
lua_pushnil(m_luaVM);
lua_setfield(m_luaVM, -2, "getenv");
lua_pushnil(m_luaVM);
lua_setfield(m_luaVM, -2, "tmpname");
lua_pop(m_luaVM, 1);

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