From 19db4e9b7c5e19398286adb4d953a4874cc39ae0 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Mon, 19 Aug 2024 16:11:36 +0200 Subject: [PATCH 1/3] Fix potential file descriptor leak in luaL_loadfile*(). Reported by Assumeru. #1249 --- src/lj_load.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lj_load.c b/src/lj_load.c index dab037b4..d92bd1b4 100644 --- a/src/lj_load.c +++ b/src/lj_load.c @@ -88,12 +88,13 @@ LUALIB_API int luaL_loadfilex(lua_State *L, const char *filename, int status; const char *chunkname; if (filename) { + chunkname = lua_pushfstring(L, "@%s", filename); ctx.fp = fopen(filename, "rb"); if (ctx.fp == NULL) { + L->top--; lua_pushfstring(L, "cannot open %s: %s", filename, strerror(errno)); return LUA_ERRFILE; } - chunkname = lua_pushfstring(L, "@%s", filename); } else { ctx.fp = stdin; chunkname = "=stdin"; From 5ca25ee83ec1b0343556cd5783ade449676b4037 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Mon, 19 Aug 2024 16:14:55 +0200 Subject: [PATCH 2/3] Correctly close VM state after early OOM during open. Reported by Assumeru. #1248 --- src/lj_gc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lj_gc.c b/src/lj_gc.c index 9c0d6797..25374d03 100644 --- a/src/lj_gc.c +++ b/src/lj_gc.c @@ -564,12 +564,11 @@ void lj_gc_finalize_cdata(lua_State *L) /* Free all remaining GC objects. */ void lj_gc_freeall(global_State *g) { - MSize i, strmask; + MSize i; /* Free everything, except super-fixed objects (the main thread). */ g->gc.currentwhite = LJ_GC_WHITES | LJ_GC_SFIXED; gc_fullsweep(g, &g->gc.root); - strmask = g->strmask; - for (i = 0; i <= strmask; i++) /* Free all string hash chains. */ + for (i = g->strmask; i != ~(MSize)0; i--) /* Free all string hash chains. */ gc_fullsweep(g, &g->strhash[i]); } From bcc6cbb188e5e2e76d4aef2d48778202f65079dc Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Mon, 19 Aug 2024 16:17:44 +0200 Subject: [PATCH 3/3] MIPS32: Fix little-endian IR_RETF. Thanks to Peter Cawley. #1250 --- src/lj_asm_mips.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lj_asm_mips.h b/src/lj_asm_mips.h index 3c99a843..3adb62f4 100644 --- a/src/lj_asm_mips.h +++ b/src/lj_asm_mips.h @@ -398,7 +398,7 @@ static void asm_retf(ASMState *as, IRIns *ir) emit_addptr(as, base, -8*delta); asm_guard(as, MIPSI_BNE, RID_TMP, ra_allock(as, i32ptr(pc), rset_exclude(RSET_GPR, base))); - emit_tsi(as, MIPSI_LW, RID_TMP, base, -8); + emit_tsi(as, MIPSI_LW, RID_TMP, base, LJ_BE ? -8 : -4); } /* -- Type conversions ---------------------------------------------------- */