]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
Correct fix for stack check when recording BC_VARG.
authorMike Pall <mike>
Thu, 8 Dec 2022 23:20:05 +0000 (00:20 +0100)
committerMike Pall <mike>
Thu, 8 Dec 2022 23:20:05 +0000 (00:20 +0100)
Reported by Yichun Zhang.

src/lj_record.c

index f7552db0132a0234359392b2794f02643e3cc9f1..dee533278e151c9cdfc95e06487b9ff6709b3c85 100644 (file)
@@ -1522,6 +1522,8 @@ static void rec_varg(jit_State *J, BCReg dst, ptrdiff_t nresults)
     } else if (dst + nresults > J->maxslot) {
       J->maxslot = dst + (BCReg)nresults;
     }
+    if (J->baseslot + J->maxslot >= LJ_MAX_JSLOTS)
+      lj_trace_err(J, LJ_TRERR_STACKOV);
     for (i = 0; i < nresults; i++)
       J->base[dst+i] = i < nvararg ? getslot(J, i - nvararg - 1) : TREF_NIL;
   } else {  /* Unknown number of varargs passed to trace. */
@@ -1602,8 +1604,6 @@ static void rec_varg(jit_State *J, BCReg dst, ptrdiff_t nresults)
       lj_trace_err_info(J, LJ_TRERR_NYIBC);
     }
   }
-  if (J->baseslot + J->maxslot >= LJ_MAX_JSLOTS)
-    lj_trace_err(J, LJ_TRERR_STACKOV);
 }
 
 /* -- Record allocations -------------------------------------------------- */