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
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 14 additions & 0 deletions Client/mods/deathmatch/logic/lua/CLuaMain.cpp
Expand Up @@ -73,6 +73,19 @@ void CLuaMain::ResetInstructionCount(void)

void CLuaMain::InitSecurity(void)
{
// Disable dangerous Lua Os library functions
static const luaL_reg osfuncs[] =
{
{ "execute", CLuaUtilDefs::DisabledFunction },
{ "rename", CLuaUtilDefs::DisabledFunction },
{ "remove", CLuaUtilDefs::DisabledFunction },
{ "exit", CLuaUtilDefs::DisabledFunction },
{ "getenv", CLuaUtilDefs::DisabledFunction },
{ "tmpname", CLuaUtilDefs::DisabledFunction },
{ NULL, NULL }
};
luaL_register(m_luaVM, "os", osfuncs);

lua_register(m_luaVM, "dofile", CLuaUtilDefs::DisabledFunction);
lua_register(m_luaVM, "loadfile", CLuaUtilDefs::DisabledFunction);
lua_register(m_luaVM, "require", CLuaUtilDefs::DisabledFunction);
Expand Down Expand Up @@ -141,6 +154,7 @@ void CLuaMain::InitVM(void)
luaopen_table(m_luaVM);
luaopen_debug(m_luaVM);
luaopen_utf8(m_luaVM);
luaopen_os(m_luaVM);

// Initialize security restrictions. Very important to prevent lua trojans and viruses!
InitSecurity();
Expand Down
14 changes: 14 additions & 0 deletions Server/mods/deathmatch/logic/lua/CLuaMain.cpp
Expand Up @@ -108,6 +108,19 @@ void CLuaMain::ResetInstructionCount(void)

void CLuaMain::InitSecurity(void)
{
// Disable dangerous Lua Os library functions
static const luaL_reg osfuncs[] =
{
{ "execute", CLuaUtilDefs::DisabledFunction },
{ "rename", CLuaUtilDefs::DisabledFunction },
{ "remove", CLuaUtilDefs::DisabledFunction },
{ "exit", CLuaUtilDefs::DisabledFunction },
{ "getenv", CLuaUtilDefs::DisabledFunction },
{ "tmpname", CLuaUtilDefs::DisabledFunction },
{ NULL, NULL }
};
luaL_register(m_luaVM, "os", osfuncs);

lua_register(m_luaVM, "dofile", CLuaUtilDefs::DisabledFunction);
lua_register(m_luaVM, "loadfile", CLuaUtilDefs::DisabledFunction);
lua_register(m_luaVM, "require", CLuaUtilDefs::DisabledFunction);
Expand Down Expand Up @@ -172,6 +185,7 @@ void CLuaMain::InitVM(void)
luaopen_table(m_luaVM);
luaopen_debug(m_luaVM);
luaopen_utf8(m_luaVM);
luaopen_os(m_luaVM);

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