From d0553753af291507823737b2c17cdb8128494f96 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 9 Aug 2017 16:00:35 +0200 Subject: [PATCH] Lua Script Sandbox - GUI part --- gtk2_ardour/luainstance.cc | 8 +++++--- gtk2_ardour/luawindow.cc | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/gtk2_ardour/luainstance.cc b/gtk2_ardour/luainstance.cc index 86acba54dd..12958e1de6 100644 --- a/gtk2_ardour/luainstance.cc +++ b/gtk2_ardour/luainstance.cc @@ -967,6 +967,7 @@ LuaInstance::~LuaInstance () void LuaInstance::init () { + lua.sandbox (false); lua.do_command ( "function ScriptManager ()" " local self = { scripts = {}, instances = {}, icons = {} }" @@ -984,7 +985,7 @@ LuaInstance::init () " assert(type(f) == 'function', 'Factory is a not a function')" " assert(type(a) == 'table' or type(a) == 'nil', 'Given argument is invalid')" " self.scripts[i] = { ['n'] = n, ['s'] = s, ['f'] = f, ['a'] = a, ['c'] = c }" - " local env = _ENV; env.f = nil env.debug = nil os.exit = nil require = nil dofile = nil loadfile = nil package = nil" + " local env = _ENV; env.f = nil env.io = nil" " self.instances[i] = load (string.dump(f, true), nil, nil, env)(a)" " if type(c) == 'function' then" " self.icons[i] = load (string.dump(c, true), nil, nil, env)(a)" @@ -1085,7 +1086,6 @@ LuaInstance::init () " manager = ScriptManager ()" " ScriptManager = nil" ); - lua_State* L = lua.getState(); try { @@ -1482,6 +1482,7 @@ LuaInstance::register_lua_slot (const std::string& name, const std::string& scri try { LuaState l; l.Print.connect (&_lua_print); + l.sandbox (true); lua_State* L = l.getState(); register_hooks (L); l.do_command ("function ardour () end"); @@ -1688,6 +1689,7 @@ void LuaCallback::init (void) { lua.Print.connect (&_lua_print); + lua.sandbox (false); lua.do_command ( "function ScriptManager ()" @@ -1699,7 +1701,7 @@ LuaCallback::init (void) " assert(type(f) == 'function', 'Factory is a not a function')" " assert(type(a) == 'table' or type(a) == 'nil', 'Given argument is invalid')" " self.script = { ['n'] = n, ['s'] = s, ['f'] = f, ['a'] = a }" - " local env = _ENV; env.f = nil env.debug = nil os.exit = nil require = nil dofile = nil loadfile = nil package = nil" + " local env = _ENV; env.f = nil env.io = nil" " self.instance = load (string.dump(f, true), nil, nil, env)(a)" " end" "" diff --git a/gtk2_ardour/luawindow.cc b/gtk2_ardour/luawindow.cc index beb2cc0356..72f0af6980 100644 --- a/gtk2_ardour/luawindow.cc +++ b/gtk2_ardour/luawindow.cc @@ -199,6 +199,7 @@ void LuaWindow::reinit_lua () delete lua; lua = new LuaState(); lua->Print.connect (sigc::mem_fun (*this, &LuaWindow::append_text)); + lua->sandbox (false); lua_State* L = lua->getState(); LuaInstance::register_classes (L);