Lua Script Sandbox - GUI part
authorRobin Gareus <robin@gareus.org>
Wed, 9 Aug 2017 14:00:35 +0000 (16:00 +0200)
committerRobin Gareus <robin@gareus.org>
Thu, 10 Aug 2017 00:25:54 +0000 (02:25 +0200)
gtk2_ardour/luainstance.cc
gtk2_ardour/luawindow.cc

index 86acba54ddc5bb268c450451724db7a8771b0022..12958e1de657a3e20851c7a01dcfade6a6e05450 100644 (file)
@@ -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"
                        ""
index beb2cc0356a2c009cd312051a15ca9aa78f75cbf..72f0af6980195e820793800344d2dcf9eac8682c 100644 (file)
@@ -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);