diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-02-17 17:20:00 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-02-17 17:20:00 -0200 |
commit | 49dae52d0808776f5861eb33efa1d13b05e44512 (patch) | |
tree | 6f2f5578539ff00b6957522e3909293ce6de58ee | |
parent | 104d249ffbf76828caa5e204979f5ddad45f2bcb (diff) | |
download | lua-49dae52d0808776f5861eb33efa1d13b05e44512.tar.gz lua-49dae52d0808776f5861eb33efa1d13b05e44512.tar.bz2 lua-49dae52d0808776f5861eb33efa1d13b05e44512.zip |
correct way to check stack space for vararg functions
-rw-r--r-- | lcode.c | 4 | ||||
-rw-r--r-- | lparser.c | 4 | ||||
-rw-r--r-- | ltm.c | 8 | ||||
-rw-r--r-- | ltm.h | 4 | ||||
-rw-r--r-- | lvm.c | 8 |
5 files changed, 14 insertions, 14 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.c,v 2.153 2018/02/09 15:16:06 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.154 2018/02/15 15:34:29 roberto Exp roberto $ |
3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -31,7 +31,7 @@ | |||
31 | 31 | ||
32 | 32 | ||
33 | /* Maximum number of registers in a Lua function (must fit in 8 bits) */ | 33 | /* Maximum number of registers in a Lua function (must fit in 8 bits) */ |
34 | #define MAXREGS 254 | 34 | #define MAXREGS 255 |
35 | 35 | ||
36 | 36 | ||
37 | #define hasjumps(e) ((e)->t != (e)->f) | 37 | #define hasjumps(e) ((e)->t != (e)->f) |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 2.176 2018/02/07 15:18:04 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 2.177 2018/02/09 15:16:06 roberto Exp roberto $ |
3 | ** Lua Parser | 3 | ** Lua Parser |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -578,8 +578,6 @@ static void close_func (LexState *ls) { | |||
578 | luaM_shrinkvector(L, f->p, f->sizep, fs->np, Proto *); | 578 | luaM_shrinkvector(L, f->p, f->sizep, fs->np, Proto *); |
579 | luaM_shrinkvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar); | 579 | luaM_shrinkvector(L, f->locvars, f->sizelocvars, fs->nlocvars, LocVar); |
580 | luaM_shrinkvector(L, f->upvalues, f->sizeupvalues, fs->nups, Upvaldesc); | 580 | luaM_shrinkvector(L, f->upvalues, f->sizeupvalues, fs->nups, Upvaldesc); |
581 | if (f->is_vararg) | ||
582 | f->maxstacksize++; /* ensure space to copy the function */ | ||
583 | ls->fs = fs->prev; | 581 | ls->fs = fs->prev; |
584 | luaC_checkGC(L); | 582 | luaC_checkGC(L); |
585 | } | 583 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.c,v 2.60 2018/02/09 15:16:06 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 2.61 2018/02/15 15:34:29 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -216,12 +216,13 @@ int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2, | |||
216 | } | 216 | } |
217 | 217 | ||
218 | 218 | ||
219 | void luaT_adjustvarargs (lua_State *L, int nfixparams, CallInfo *ci) { | 219 | void luaT_adjustvarargs (lua_State *L, int nfixparams, CallInfo *ci, |
220 | Proto *p) { | ||
220 | int i; | 221 | int i; |
221 | int actual = cast_int(L->top - ci->func) - 1; /* number of arguments */ | 222 | int actual = cast_int(L->top - ci->func) - 1; /* number of arguments */ |
222 | int nextra = actual - nfixparams; /* number of extra arguments */ | 223 | int nextra = actual - nfixparams; /* number of extra arguments */ |
223 | ci->u.l.nextraargs = nextra; | 224 | ci->u.l.nextraargs = nextra; |
224 | checkstackGC(L, nfixparams + 1); | 225 | checkstackGC(L, p->maxstacksize + 1); |
225 | /* copy function to the top of the stack */ | 226 | /* copy function to the top of the stack */ |
226 | setobjs2s(L, L->top++, ci->func); | 227 | setobjs2s(L, L->top++, ci->func); |
227 | /* move fixed parameters to the top of the stack */ | 228 | /* move fixed parameters to the top of the stack */ |
@@ -231,6 +232,7 @@ void luaT_adjustvarargs (lua_State *L, int nfixparams, CallInfo *ci) { | |||
231 | } | 232 | } |
232 | ci->func += actual + 1; | 233 | ci->func += actual + 1; |
233 | ci->top += actual + 1; | 234 | ci->top += actual + 1; |
235 | lua_assert(L->top <= ci->top && ci->top <= L->stack_last); | ||
234 | } | 236 | } |
235 | 237 | ||
236 | 238 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.h,v 2.30 2018/02/07 15:18:04 roberto Exp roberto $ | 2 | ** $Id: ltm.h,v 2.31 2018/02/09 15:16:06 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -79,7 +79,7 @@ LUAI_FUNC int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2, | |||
79 | int inv, TMS event); | 79 | int inv, TMS event); |
80 | 80 | ||
81 | LUAI_FUNC void luaT_adjustvarargs (lua_State *L, int nfixparams, | 81 | LUAI_FUNC void luaT_adjustvarargs (lua_State *L, int nfixparams, |
82 | struct CallInfo *ci); | 82 | struct CallInfo *ci, Proto *p); |
83 | LUAI_FUNC void luaT_getvarargs (lua_State *L, struct CallInfo *ci, | 83 | LUAI_FUNC void luaT_getvarargs (lua_State *L, struct CallInfo *ci, |
84 | StkId where, int wanted); | 84 | StkId where, int wanted); |
85 | 85 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.339 2018/02/09 15:16:06 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.340 2018/02/15 15:34:29 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -1713,13 +1713,13 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1713 | vmbreak; | 1713 | vmbreak; |
1714 | } | 1714 | } |
1715 | vmcase(OP_PREPVARARG) { | 1715 | vmcase(OP_PREPVARARG) { |
1716 | luaT_adjustvarargs(L, GETARG_A(i), ci); | 1716 | luaT_adjustvarargs(L, GETARG_A(i), ci, cl->p); |
1717 | updatetrap(ci); | 1717 | updatetrap(ci); |
1718 | if (trap) { | 1718 | if (trap) { |
1719 | luaD_hookcall(L, ci); | 1719 | luaD_hookcall(L, ci); |
1720 | L->oldpc = pc + 1; /* next opcode will be seen as a new line */ | 1720 | L->oldpc = pc + 1; /* next opcode will be seen as a "new" line */ |
1721 | } | 1721 | } |
1722 | updatebase(ci); | 1722 | updatebase(ci); /* function has new base after adjustment */ |
1723 | vmbreak; | 1723 | vmbreak; |
1724 | } | 1724 | } |
1725 | vmcase(OP_EXTRAARG) { | 1725 | vmcase(OP_EXTRAARG) { |