Use after free in 'luaV_finishset'

If a metatable is a weak table, its __newindex field could be collected
by an emergency collection while being used in 'luaV_finishset'. (This
bug has similarities with bug 5.3.2-1, fixed in commit a272fa66.)
This commit is contained in:
Roberto Ierusalimschy
2025-03-13 15:30:52 -03:00
parent c931d86e98
commit 22974326ca
3 changed files with 25 additions and 1 deletions

5
lapi.c
View File

@@ -681,6 +681,11 @@ static int auxgetstr (lua_State *L, const TValue *t, const char *k) {
}
/*
** The following function assumes that the registry cannot be a weak
** table, so that en mergency collection while using the global table
** cannot collect it.
*/
static void getGlobalTable (lua_State *L, TValue *gt) {
Table *registry = hvalue(&G(L)->l_registry);
lu_byte tag = luaH_getint(registry, LUA_RIDX_GLOBALS, gt);