lua-users home
lua-l archive

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


In https://github.com/lua/lua/blob/e8deac5a41ffd644aaa78fda6d4bd5caa72cb077/ldo.c#L391-L393 a use after free can occure if checkstackGCp calls a garbage collector which rehashes the metatable into which the tm pointer points.

To make the example more reliable lua was compiled with:
TESTS= -DLUA_USER_H='"ltests.h"' -O0 -g -DHARDSTACKTESTS=1 -DHARDMEMTESTS=1 -fsanitize=address

in which case the following code will cause a heap-use-after-free error by address sanitizer:

local x = {}
x.__call = function() end
setmetatable(x, x)

do
setmetatable({},{
    __gc = function()
        for i = 1, 100 do
            x["x"..i] = 1
        end
    end
})
end

return x()

Regards,
Xmilia