Skip to content

Commit

Permalink
Bug: cannot allow the call 'debug.getinfo(0, ">")'
Browse files Browse the repository at this point in the history
A 'what' argument starting with '>' indicates that there is a function
in the C stack, which won't be there if the first argument is not a
function.
  • Loading branch information
roberto-ieru committed Feb 15, 2021
1 parent bc97000 commit 38cc7d4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions ldblib.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ static int db_getinfo (lua_State *L) {
lua_State *L1 = getthread(L, &arg);
const char *options = luaL_optstring(L, arg+2, "flnSrtu");
checkstack(L, L1, 3);
luaL_argcheck(L, options[0] != '>', arg + 2, "invalid option '>'");
if (lua_isfunction(L, arg + 1)) { /* info about a function? */
options = lua_pushfstring(L, ">%s", options); /* add '>' to 'options' */
lua_pushvalue(L, arg + 1); /* move function to 'L1' stack */
Expand Down
1 change: 1 addition & 0 deletions testes/db.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ end

do
assert(not pcall(debug.getinfo, print, "X")) -- invalid option
assert(not pcall(debug.getinfo, 0, ">")) -- invalid option
assert(not debug.getinfo(1000)) -- out of range level
assert(not debug.getinfo(-1)) -- out of range level
local a = debug.getinfo(print)
Expand Down

0 comments on commit 38cc7d4

Please sign in to comment.