mirror of
https://github.com/lua/lua.git
synced 2026-07-22 22:19:06 +00:00
Bug: message handler can be overwritten
A __close metamethod can overwrite a message handler in the stack when closing a thread or a state.
This commit is contained in:
@@ -493,6 +493,25 @@ assert(not pcall(a, a))
|
||||
a = nil
|
||||
|
||||
|
||||
do
|
||||
-- bug in 5.4: thread can use message handler higher in the stack
|
||||
-- than the variable being closed
|
||||
local c = coroutine.create(function()
|
||||
local clo <close> = setmetatable({}, {__close=function()
|
||||
local x = 134 -- will overwrite message handler
|
||||
error(x)
|
||||
end})
|
||||
-- yields coroutine but leaves a new message handler for it,
|
||||
-- that would be used when closing the coroutine (except that it
|
||||
-- will be overwritten)
|
||||
xpcall(coroutine.yield, function() return "XXX" end)
|
||||
end)
|
||||
|
||||
assert(coroutine.resume(c)) -- start coroutine
|
||||
local st, msg = coroutine.close(c)
|
||||
assert(not st and msg == 134)
|
||||
end
|
||||
|
||||
-- access to locals of erroneous coroutines
|
||||
local x = coroutine.create (function ()
|
||||
local a = 10
|
||||
|
||||
Reference in New Issue
Block a user