lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, Jan 12, 2010 at 7:25 PM, David Kolf <kolf@gmx.de> wrote:
>
> But now I noticed another problem which makes it look to me like you
> can't use that for sandboxes at all. Consider the following code:
>
>  code = "local dummy = nil end; do os.remove (\"something\")"
>  f = loadstring ("in ... do " .. code .. " end")
>
> The new function f would read (indented for clarity):
>  in ... do
>    local dummy = nil
>  end;
>  do
>    os.remove ("something")
>  end
>
> Or did I miss something again?

Try

f = loadin("in ... do " .. code .. " end", {})

Now the code injected after in's scope is running in an empty
environment, so cannot do anything problematic but doing an infinite
loop. The injected code can still acess the in's environment through
..., of course, but this is what you want anyway. :-)

--
Fabio Mascarenhas