Do not call message handler in xpcall if allocation error

This commit is contained in:
Alex Orlenko 2023-03-28 22:39:04 +01:00
parent be52bd91e4
commit 99ab30cf04
No known key found for this signature in database
GPG key ID: 4C150C250863B96D
3 changed files with 19 additions and 2 deletions

View file

@ -550,8 +550,8 @@ int luaD_pcall(lua_State* L, Pfunc func, void* u, ptrdiff_t old_top, ptrdiff_t e
int status = luaD_rawrunprotected(L, func, u); int status = luaD_rawrunprotected(L, func, u);
if (status != 0) if (status != 0)
{ {
// call user-defined error function (used in xpcall) // call user-defined error function (used in xpcall) except if allocation error
if (ef) if (ef && status != LUA_ERRMEM)
{ {
// if errfunc fails, we fail with "error in error handling" // if errfunc fails, we fail with "error in error handling"
if (luaD_rawrunprotected(L, callerrfunc, restorestack(L, ef)) != 0) if (luaD_rawrunprotected(L, callerrfunc, restorestack(L, ef)) != 0)

View file

@ -1078,6 +1078,11 @@ TEST_CASE("ExceptionObject")
ExceptionResult result = captureException(L, "large_allocation_error"); ExceptionResult result = captureException(L, "large_allocation_error");
CHECK(result.exceptionGenerated); CHECK(result.exceptionGenerated);
} }
{
ExceptionResult result = captureException(L, "large_allocation_error_without_handler");
CHECK(result.exceptionGenerated);
}
} }
#endif #endif

View file

@ -32,4 +32,16 @@ function large_allocation_error()
table.create(1000000) table.create(1000000)
end end
function large_allocation_error_without_handler()
-- Create a table that will require more memory than the test's memory
-- allocator will allow.
local msgh_called = false
local ok, err = xpcall(table.create, function() msgh_called = true end, 1000000)
-- Check that message handler was not called for memory allocation error
if not ok and not msgh_called then
-- Propagate error
error(err)
end
end
return('OK') return('OK')