Avoid underflows in 'luaF_getlocalname'

A call like 'debug.getlocal(test, -2147483648)' could decrement
-2147483648, causing an underflow. (As this happens in a debug function,
the fix was not strictly necessary, but it has no cost in the generated
code.)
This commit is contained in:
Roberto I
2026-10-12 16:12:40 -03:00
parent 745b96db54
commit 80f3ecc44f
5 changed files with 8 additions and 7 deletions
+3 -3
View File
@@ -202,7 +202,7 @@ const char *luaG_findlocal (lua_State *L, CallInfo *ci, int n, StkId *pos) {
if (n < 0) /* access to vararg values? */
return findvararg(ci, n, pos);
else
name = luaF_getlocalname(ci_func(ci)->p, n, currentpc(ci));
name = luaF_getlocalname(ci_func(ci)->p, cast_uint(n), currentpc(ci));
}
if (name == NULL) { /* no 'standard' name? */
StkId limit = (ci == L->ci) ? L->top.p : ci->next->func.p;
@@ -226,7 +226,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
if (!isLfunction(s2v(L->top.p - 1))) /* not a Lua function? */
name = NULL;
else /* consider live variables at function start (parameters) */
name = luaF_getlocalname(clLvalue(s2v(L->top.p - 1))->p, n, 0);
name = luaF_getlocalname(clLvalue(s2v(L->top.p - 1))->p, cast_uint(n), 0);
}
else { /* active function; get information through 'ar' */
StkId pos = NULL; /* to avoid warnings */
@@ -505,7 +505,7 @@ static const char *kname (const Proto *p, int index, const char **name) {
static const char *basicgetobjname (const Proto *p, int *ppc, int reg,
const char **name) {
int pc = *ppc;
*name = luaF_getlocalname(p, reg + 1, pc);
*name = luaF_getlocalname(p, cast_uint(reg + 1), pc);
if (*name) /* is a local? */
return strlocal;
/* else try symbolic execution */