mirror of
https://github.com/glest/glest-source.git
synced 2025-08-16 21:33:59 +02:00
- added first round of security sandboxing for lua scripts (disable the os library)
This commit is contained in:
@@ -411,20 +411,36 @@ void ScriptManager::init(World* world, GameCamera *gameCamera, const XmlNode *ro
|
|||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
// Setup global functions and vars here
|
try {
|
||||||
luaScript.beginCall("global");
|
// Setup global functions and vars here
|
||||||
luaScript.endCall();
|
luaScript.beginCall("global");
|
||||||
|
|
||||||
//call startup function
|
|
||||||
if(this->rootNode == NULL) {
|
|
||||||
luaScript.beginCall("startup");
|
|
||||||
luaScript.endCall();
|
luaScript.endCall();
|
||||||
}
|
|
||||||
else {
|
|
||||||
loadGame(this->rootNode);
|
|
||||||
this->rootNode = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
//call startup function
|
||||||
|
if(this->rootNode == NULL) {
|
||||||
|
luaScript.beginCall("startup");
|
||||||
|
luaScript.endCall();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
loadGame(this->rootNode);
|
||||||
|
this->rootNode = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(const megaglest_runtime_error &ex) {
|
||||||
|
string sErrBuf = "";
|
||||||
|
//if(ex.wantStackTrace() == true) {
|
||||||
|
char szErrBuf[8096]="";
|
||||||
|
sprintf(szErrBuf,"In [%s::%s %d]",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
sErrBuf = string(szErrBuf) + string("\nerror [") + string(ex.what()) + string("]\n");
|
||||||
|
//}
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str());
|
||||||
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str());
|
||||||
|
|
||||||
|
ScriptManager_STREFLOP_Wrapper streflopWrapper;
|
||||||
|
|
||||||
|
messageQueue.push_back(ScriptManagerMessage(sErrBuf.c_str(), "error"));
|
||||||
|
onMessageBoxOk(false);
|
||||||
|
}
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugLUA).enabled) SystemFlags::OutputDebug(SystemFlags::debugLUA,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -49,6 +49,7 @@
|
|||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include "string_utils.h"
|
#include "string_utils.h"
|
||||||
#include "auto_test.h"
|
#include "auto_test.h"
|
||||||
|
#include "lua_script.h"
|
||||||
|
|
||||||
// To handle signal catching
|
// To handle signal catching
|
||||||
#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD)
|
#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD)
|
||||||
@@ -3206,6 +3207,10 @@ int glestMain(int argc, char** argv) {
|
|||||||
Config &config = Config::getInstance();
|
Config &config = Config::getInstance();
|
||||||
setupGameItemPaths(argc, argv, &config);
|
setupGameItemPaths(argc, argv, &config);
|
||||||
|
|
||||||
|
if(config.getBool("DisableLuaSandbox","false") == true) {
|
||||||
|
LuaScript::setDisableSandbox(true);
|
||||||
|
}
|
||||||
|
|
||||||
Socket::setBroadCastPort(config.getInt("BroadcastPort",intToStr(Socket::getBroadCastPort()).c_str()));
|
Socket::setBroadCastPort(config.getInt("BroadcastPort",intToStr(Socket::getBroadCastPort()).c_str()));
|
||||||
|
|
||||||
Socket::disableNagle = config.getBool("DisableNagle","false");
|
Socket::disableNagle = config.getBool("DisableNagle","false");
|
||||||
|
@@ -42,12 +42,16 @@ private:
|
|||||||
string sandboxWrapperFunctionName;
|
string sandboxWrapperFunctionName;
|
||||||
string sandboxCode;
|
string sandboxCode;
|
||||||
|
|
||||||
|
static bool disableSandbox;
|
||||||
|
|
||||||
void DumpGlobals();
|
void DumpGlobals();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LuaScript();
|
LuaScript();
|
||||||
~LuaScript();
|
~LuaScript();
|
||||||
|
|
||||||
|
static void setDisableSandbox(bool value) { disableSandbox = value; }
|
||||||
|
|
||||||
void loadCode(string code, string name);
|
void loadCode(string code, string name);
|
||||||
|
|
||||||
void beginCall(string functionName);
|
void beginCall(string functionName);
|
||||||
|
@@ -45,6 +45,8 @@ public:
|
|||||||
// class LuaScript
|
// class LuaScript
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
|
bool LuaScript::disableSandbox = false;
|
||||||
|
|
||||||
LuaScript::LuaScript() {
|
LuaScript::LuaScript() {
|
||||||
Lua_STREFLOP_Wrapper streflopWrapper;
|
Lua_STREFLOP_Wrapper streflopWrapper;
|
||||||
|
|
||||||
@@ -56,11 +58,24 @@ LuaScript::LuaScript() {
|
|||||||
|
|
||||||
luaL_openlibs(luaState);
|
luaL_openlibs(luaState);
|
||||||
|
|
||||||
if(luaState==NULL){
|
if(luaState == NULL) {
|
||||||
throw megaglest_runtime_error("Can not allocate lua state");
|
throw megaglest_runtime_error("Can not allocate lua state");
|
||||||
}
|
}
|
||||||
|
|
||||||
argumentCount= -1;
|
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()
|
void LuaScript::DumpGlobals()
|
||||||
|
Reference in New Issue
Block a user