Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/mit/lua/dist/src lua: aply upstream bugfix for "'lu...



details:   https://anonhg.NetBSD.org/src/rev/5b423defd36c
branches:  trunk
changeset: 374298:5b423defd36c
user:      nikita <nikita%NetBSD.org@localhost>
date:      Mon Apr 17 19:54:19 2023 +0000

description:
lua: aply upstream bugfix for "'lua_settop' may use a pointer to stack invalidated by 'luaF_close'."

diffstat:

 external/mit/lua/dist/src/lapi.c  |   7 +++----
 external/mit/lua/dist/src/ldo.c   |  14 +++++++-------
 external/mit/lua/dist/src/lfunc.c |   7 ++++---
 external/mit/lua/dist/src/lfunc.h |   4 ++--
 4 files changed, 16 insertions(+), 16 deletions(-)

diffs (114 lines):

diff -r f3d5ad5cb6ce -r 5b423defd36c external/mit/lua/dist/src/lapi.c
--- a/external/mit/lua/dist/src/lapi.c  Mon Apr 17 19:35:36 2023 +0000
+++ b/external/mit/lua/dist/src/lapi.c  Mon Apr 17 19:54:19 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lapi.c,v 1.13 2023/04/16 20:46:17 nikita Exp $ */
+/*     $NetBSD: lapi.c,v 1.14 2023/04/17 19:54:19 nikita Exp $ */
 
 /*
 ** Id: lapi.c 
@@ -208,7 +208,7 @@ LUA_API void lua_settop (lua_State *L, i
   newtop = L->top + diff;
   if (diff < 0 && L->tbclist >= newtop) {
     lua_assert(hastocloseCfunc(ci->nresults));
-    luaF_close(L, newtop, CLOSEKTOP, 0);
+    newtop = luaF_close(L, newtop, CLOSEKTOP, 0);
   }
   L->top = newtop;  /* correct top only after closing any upvalue */
   lua_unlock(L);
@@ -221,8 +221,7 @@ LUA_API void lua_closeslot (lua_State *L
   level = index2stack(L, idx);
   api_check(L, hastocloseCfunc(L->ci->nresults) && L->tbclist == level,
      "no variable to close at given level");
-  luaF_close(L, level, CLOSEKTOP, 0);
-  level = index2stack(L, idx);  /* stack may be moved */
+  level = luaF_close(L, level, CLOSEKTOP, 0);
   setnilvalue(s2v(level));
   lua_unlock(L);
 }
diff -r f3d5ad5cb6ce -r 5b423defd36c external/mit/lua/dist/src/ldo.c
--- a/external/mit/lua/dist/src/ldo.c   Mon Apr 17 19:35:36 2023 +0000
+++ b/external/mit/lua/dist/src/ldo.c   Mon Apr 17 19:54:19 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ldo.c,v 1.10 2023/04/16 20:46:17 nikita Exp $  */
+/*     $NetBSD: ldo.c,v 1.11 2023/04/17 19:54:19 nikita Exp $  */
 
 /*
 ** Id: ldo.c 
@@ -431,14 +431,15 @@ l_sinline void moveresults (lua_State *L
       break;
     default:  /* two/more results and/or to-be-closed variables */
       if (hastocloseCfunc(wanted)) {  /* to-be-closed variables? */
-        ptrdiff_t savedres = savestack(L, res);
         L->ci->callstatus |= CIST_CLSRET;  /* in case of yields */
         L->ci->u2.nres = nres;
-        luaF_close(L, res, CLOSEKTOP, 1);
+        res = luaF_close(L, res, CLOSEKTOP, 1);
         L->ci->callstatus &= ~CIST_CLSRET;
-        if (L->hookmask)  /* if needed, call hook after '__close's */
+        if (L->hookmask) {  /* if needed, call hook after '__close's */
+          ptrdiff_t savedres = savestack(L, res);
           rethook(L, L->ci, nres);
-        res = restorestack(L, savedres);  /* close and hook can move stack */
+          res = restorestack(L, savedres);  /* hook can move stack */
+        }
         wanted = decodeNresults(wanted);
         if (wanted == LUA_MULTRET)
           wanted = nres;  /* we want all results */
@@ -655,8 +656,7 @@ static int finishpcallk (lua_State *L,  
   else {  /* error */
     StkId func = restorestack(L, ci->u2.funcidx);
     L->allowhook = getoah(ci->callstatus);  /* restore 'allowhook' */
-    luaF_close(L, func, status, 1);  /* can yield or raise an error */
-    func = restorestack(L, ci->u2.funcidx);  /* stack may be moved */
+    func = luaF_close(L, func, status, 1);  /* can yield or raise an error */
     luaD_seterrorobj(L, status, func);
     luaD_shrinkstack(L);   /* restore stack size in case of overflow */
     setcistrecst(ci, LUA_OK);  /* clear original status */
diff -r f3d5ad5cb6ce -r 5b423defd36c external/mit/lua/dist/src/lfunc.c
--- a/external/mit/lua/dist/src/lfunc.c Mon Apr 17 19:35:36 2023 +0000
+++ b/external/mit/lua/dist/src/lfunc.c Mon Apr 17 19:54:19 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfunc.c,v 1.9 2023/04/16 20:46:17 nikita Exp $ */
+/*     $NetBSD: lfunc.c,v 1.10 2023/04/17 19:54:19 nikita Exp $        */
 
 /*
 ** Id: lfunc.c 
@@ -227,9 +227,9 @@ static void poptbclist (lua_State *L) {
 
 /*
 ** Close all upvalues and to-be-closed variables up to the given stack
-** level.
+** level. Return restored 'level'.
 */
-void luaF_close (lua_State *L, StkId level, int status, int yy) {
+StkId luaF_close (lua_State *L, StkId level, int status, int yy) {
   ptrdiff_t levelrel = savestack(L, level);
   luaF_closeupval(L, level);  /* first, close the upvalues */
   while (L->tbclist >= level) {  /* traverse tbc's down to that level */
@@ -238,6 +238,7 @@ void luaF_close (lua_State *L, StkId lev
     prepcallclosemth(L, tbc, status, yy);  /* close variable */
     level = restorestack(L, levelrel);
   }
+  return level;
 }
 
 
diff -r f3d5ad5cb6ce -r 5b423defd36c external/mit/lua/dist/src/lfunc.h
--- a/external/mit/lua/dist/src/lfunc.h Mon Apr 17 19:35:36 2023 +0000
+++ b/external/mit/lua/dist/src/lfunc.h Mon Apr 17 19:54:19 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfunc.h,v 1.9 2023/04/16 20:46:17 nikita Exp $ */
+/*     $NetBSD: lfunc.h,v 1.10 2023/04/17 19:54:19 nikita Exp $        */
 
 /*
 ** Id: lfunc.h 
@@ -56,7 +56,7 @@ LUAI_FUNC void luaF_initupvals (lua_Stat
 LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
 LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level);
 LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level);
-LUAI_FUNC void luaF_close (lua_State *L, StkId level, int status, int yy);
+LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, int status, int yy);
 LUAI_FUNC void luaF_unlinkupval (UpVal *uv);
 LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
 LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,



Home | Main Index | Thread Index | Old Index