From fcd4d4a7aad2102cc4de5a6fe395820287f80c32 Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Mon, 12 Jan 2026 17:23:27 +0100 Subject: [PATCH] BUG/MINOR: hlua_fcn: ensure Patref:add_bulk() is given a table object before using it As reported by GH user @kanashimia in GH #3241, providing anything else than a table to Patref:add_bulk() method could cause a segfault because we were calling lua_next() with the lua object without ensuring it actually is a table. Let's add the missing lua_istable() check on the stack object before calling lua_next() function on it. It should be backported up to 3.2 with 884dc62 ("MINOR: hlua_fcn: add Patref:add_bulk()") --- src/hlua_fcn.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/hlua_fcn.c b/src/hlua_fcn.c index 5026e30be..6fc0d5d8b 100644 --- a/src/hlua_fcn.c +++ b/src/hlua_fcn.c @@ -2796,6 +2796,11 @@ static int _hlua_patref_add_bulk(lua_State *L, int status, lua_KContext ctx) int count = 0; int ret; + if (!lua_istable(L, 2)) { + luaL_argerror(L, 2, "argument is expected to be a table"); + return 0; // not reached + } + if ((ref->flags & HLUA_PATREF_FL_GEN) && pat_ref_may_commit(ref->ptr, ref->curr_gen)) curr_gen = ref->curr_gen;