Handle OOM error on stack resize in coroutine.resume and lua_checkstack.

Thanks to Peter Cawley. #1066
This commit is contained in:
Mike Pall
2023-09-21 04:40:48 +02:00
parent e86990f7f2
commit a5d2f70c73
4 changed files with 23 additions and 2 deletions

View File

@@ -104,7 +104,12 @@ LUA_API int lua_checkstack(lua_State *L, int size)
if (size > LUAI_MAXCSTACK || (L->top - L->base + size) > LUAI_MAXCSTACK) {
return 0; /* Stack overflow. */
} else if (size > 0) {
lj_state_checkstack(L, (MSize)size);
int avail = (int)(mref(L->maxstack, TValue) - L->top);
if (size > avail &&
lj_state_cpgrowstack(L, (MSize)(size - avail)) != LUA_OK) {
L->top--;
return 0; /* Out of memory. */
}
}
return 1;
}