diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-03-17 16:14:17 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-03-17 16:14:17 -0300 |
| commit | 3fe7be956f23385aa1950dc31e2f25127ccfc0ea (patch) | |
| tree | 1994e4fae4370d1db3e9c767338bd4f8a28e74fd /testes/coroutine.lua | |
| parent | 983bc433e6a60cbc4fe3a16f1d4713bacb8e3509 (diff) | |
| download | lua-3fe7be956f23385aa1950dc31e2f25127ccfc0ea.tar.gz lua-3fe7be956f23385aa1950dc31e2f25127ccfc0ea.tar.bz2 lua-3fe7be956f23385aa1950dc31e2f25127ccfc0ea.zip | |
Bug: message handler can be overwritten
A __close metamethod can overwrite a message handler in the stack
when closing a thread or a state.
Diffstat (limited to 'testes/coroutine.lua')
| -rw-r--r-- | testes/coroutine.lua | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/testes/coroutine.lua b/testes/coroutine.lua index e566c86e..03e04451 100644 --- a/testes/coroutine.lua +++ b/testes/coroutine.lua | |||
| @@ -493,6 +493,25 @@ assert(not pcall(a, a)) | |||
| 493 | a = nil | 493 | a = nil |
| 494 | 494 | ||
| 495 | 495 | ||
| 496 | do | ||
| 497 | -- bug in 5.4: thread can use message handler higher in the stack | ||
| 498 | -- than the variable being closed | ||
| 499 | local c = coroutine.create(function() | ||
| 500 | local clo <close> = setmetatable({}, {__close=function() | ||
| 501 | local x = 134 -- will overwrite message handler | ||
| 502 | error(x) | ||
| 503 | end}) | ||
| 504 | -- yields coroutine but leaves a new message handler for it, | ||
| 505 | -- that would be used when closing the coroutine (except that it | ||
| 506 | -- will be overwritten) | ||
| 507 | xpcall(coroutine.yield, function() return "XXX" end) | ||
| 508 | end) | ||
| 509 | |||
| 510 | assert(coroutine.resume(c)) -- start coroutine | ||
| 511 | local st, msg = coroutine.close(c) | ||
| 512 | assert(not st and msg == 134) | ||
| 513 | end | ||
| 514 | |||
| 496 | -- access to locals of erroneous coroutines | 515 | -- access to locals of erroneous coroutines |
| 497 | local x = coroutine.create (function () | 516 | local x = coroutine.create (function () |
| 498 | local a = 10 | 517 | local a = 10 |
