lua-users home
lua-l archive

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


On Mon, Aug 23, 2010 at 1:54 PM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> Consider the following code:
>>
>> print(loadin({}, string.dump(function()return end))) --> table
>>
>> The loadin function in 5.2-work4 seems to assume that there will be an
>> upvalue to set, as it doesn't check the return value of
>> lua_setupvalue, and hence leaves the new environment on the top of the
>> stack if the loaded chunk has no upvalues, thus causing the return
>> value to be the environment rather than the loaded chunk. The
>> documentation for loadin does explicitly mention that it sets the
>> first upvalue, so the correct behaviour is not really specified, but I
>> suspect that it should be to not set any upvalues and return the
>> loaded chunk.
>
> I think it should raise an error if the chunk does not have a first
> upvalue or if this upvalue is not called _ENV.

Well if you're simply trying to sandbox foreign code, you can't really
anticipate whether it will actually use globals or not... (I don't
think an error would be helpful, just report success?)


-- 
- Patrick Donnelly