[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Modify Lua interpreter to implement a sandbox script language
- From: Andrew Gierth <andrew@...>
- Date: Wed, 05 Sep 2018 12:57:08 +0100
>>>>> "Brice" == Brice André <brice@famille-andre.be> writes:
Andrew> setfenv doesn't exist in 5.2+; in current versions you use the
Andrew> environment parameter to load() instead.
Brice> I tried the "sandbox enviroment" method you propopsed. After
Brice> some googling, I tried the following code (with call to
Brice> "PushSandboxEnvironmentTable" inserted between the
Brice> "luaL_loadbuffer" and the "lua_pcall" to set a local environment
Brice> with only function "print" available.
Brice> But at execution with this code, lua is complaining that "print"
Brice> does not exist.
It ought to be complaining that "print" is not a function, because what
you pushed in the environment table is a string not a closure.
If you want to see my actual code, then:
https://github.com/RhodiumToad/pllua-ng/blob/master/src/trusted.c
(this file is the one setting up the sandbox environment)
(also see compile.c:pllua_prepare_function which actually sets the
environment upvalue, though in my case it's not supplying the sandbox
table directly but rather a metatable whose __index points to the
sandbox's "global" table; some code in init.c, elog.c and error.c may
also be relevant.)
--
Andrew.