Explicit limit for number of results in a call

The parameter 'nresults' in 'lua_call' and similar functions has a
limit of 250. It already had an undocumented (and unchecked) limit of
SHRT_MAX, but it is seldom larger than 2.
This commit is contained in:
Roberto Ierusalimschy
2024-07-18 14:44:40 -03:00
parent cd4de92762
commit a546138d15
3 changed files with 17 additions and 4 deletions

9
lapi.c
View File

@@ -1022,10 +1022,15 @@ LUA_API int lua_setiuservalue (lua_State *L, int idx, int n) {
*/
#define MAXRESULTS 250
#define checkresults(L,na,nr) \
api_check(L, (nr) == LUA_MULTRET \
(api_check(L, (nr) == LUA_MULTRET \
|| (L->ci->top.p - L->top.p >= (nr) - (na)), \
"results from function overflow current stack size")
"results from function overflow current stack size"), \
api_check(L, LUA_MULTRET <= (nr) && (nr) <= MAXRESULTS, \
"invalid number of results"))
LUA_API void lua_callk (lua_State *L, int nargs, int nresults,