- added first round of security sandboxing for lua scripts (disable the os library)

This commit is contained in:
Mark Vejvoda
2012-10-11 05:17:37 +00:00
parent 8cc9c760e1
commit e3e3832070
4 changed files with 53 additions and 13 deletions

View File

@@ -45,6 +45,8 @@ public:
// class LuaScript
// =====================================================
bool LuaScript::disableSandbox = false;
LuaScript::LuaScript() {
Lua_STREFLOP_Wrapper streflopWrapper;
@@ -56,11 +58,24 @@ LuaScript::LuaScript() {
luaL_openlibs(luaState);
if(luaState==NULL){
if(luaState == NULL) {
throw megaglest_runtime_error("Can not allocate lua state");
}
argumentCount= -1;
if(disableSandbox == false) {
lua_getglobal(luaState, "os");
lua_pushnil(luaState);
lua_setfield(luaState, -2, "execute");
lua_pushnil(luaState);
lua_setfield(luaState, -2, "rename");
lua_pushnil(luaState);
lua_setfield(luaState, -2, "remove");
lua_pushnil(luaState);
lua_setfield(luaState, -2, "exit");
lua_pop(luaState, 1);
}
}
void LuaScript::DumpGlobals()