Browse Source

Bug: finalizers can be called with an invalid stack

The call to 'checkstackGC' can run finalizers, which will find an
inconsistent CallInfo, as 'ci' is half updated at the point of call.
Roberto Ierusalimschy 4 years ago
parent
commit
cf613cdc6f
1 changed files with 1 additions and 1 deletions
  1. 1 1
      ldo.c

+ 1 - 1
ldo.c

@@ -530,10 +530,10 @@ int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
       int fsize = p->maxstacksize;  /* frame size */
       int fsize = p->maxstacksize;  /* frame size */
       int nfixparams = p->numparams;
       int nfixparams = p->numparams;
       int i;
       int i;
+      checkstackGCp(L, fsize - delta, func);
       ci->func -= delta;  /* restore 'func' (if vararg) */
       ci->func -= delta;  /* restore 'func' (if vararg) */
       for (i = 0; i < narg1; i++)  /* move down function and arguments */
       for (i = 0; i < narg1; i++)  /* move down function and arguments */
         setobjs2s(L, ci->func + i, func + i);
         setobjs2s(L, ci->func + i, func + i);
-      checkstackGC(L, fsize);
       func = ci->func;  /* moved-down function */
       func = ci->func;  /* moved-down function */
       for (; narg1 <= nfixparams; narg1++)
       for (; narg1 <= nfixparams; narg1++)
         setnilvalue(s2v(func + narg1));  /* complete missing arguments */
         setnilvalue(s2v(func + narg1));  /* complete missing arguments */