summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-08-03 16:25:28 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-08-03 16:25:28 -0300
commitb5bc89846721375fe30772eb8c5ab2786f362bf9 (patch)
tree2a4dd535e38dc79efe6fc2b355b452aa4c5db572
parent092f66fb0590f543ee5c45156ddabaddc7222a92 (diff)
downloadlua-github-b5bc89846721375fe30772eb8c5ab2786f362bf9.tar.gz
Fixed bug: Negation overflow in getlocal/setlocal
-rw-r--r--ldebug.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/ldebug.c b/ldebug.c
index e1389296..bb0e1d4a 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -133,10 +133,11 @@ static const char *upvalname (Proto *p, int uv) {
static const char *findvararg (CallInfo *ci, int n, StkId *pos) {
int nparams = clLvalue(ci->func)->p->numparams;
- if (n >= cast_int(ci->u.l.base - ci->func) - nparams)
+ int nvararg = cast_int(ci->u.l.base - ci->func) - nparams;
+ if (n <= -nvararg)
return NULL; /* no such vararg */
else {
- *pos = ci->func + nparams + n;
+ *pos = ci->func + nparams - n;
return "(*vararg)"; /* generic name for any vararg */
}
}
@@ -148,7 +149,7 @@ static const char *findlocal (lua_State *L, CallInfo *ci, int n,
StkId base;
if (isLua(ci)) {
if (n < 0) /* access to vararg values? */
- return findvararg(ci, -n, pos);
+ return findvararg(ci, n, pos);
else {
base = ci->u.l.base;
name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci));