diff options
author | Mike Pall <mike> | 2023-09-21 01:58:43 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2023-09-21 01:58:43 +0200 |
commit | d2f6c55b05c716e5dbb479b7e684abaee7cf6e12 (patch) | |
tree | ffa0d11d3ff996a4f6aee476edafc6f51049993e | |
parent | 9760984638d241531ff8a9eef259aad2272f0f75 (diff) | |
download | luajit-d2f6c55b05c716e5dbb479b7e684abaee7cf6e12.tar.gz luajit-d2f6c55b05c716e5dbb479b7e684abaee7cf6e12.tar.bz2 luajit-d2f6c55b05c716e5dbb479b7e684abaee7cf6e12.zip |
Cleanup stack overflow handling.
Reported by Peter Cawley. #962
-rw-r--r-- | src/lj_state.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/lj_state.c b/src/lj_state.c index d7befaff..1a3473b4 100644 --- a/src/lj_state.c +++ b/src/lj_state.c | |||
@@ -97,8 +97,17 @@ void lj_state_shrinkstack(lua_State *L, MSize used) | |||
97 | void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need) | 97 | void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need) |
98 | { | 98 | { |
99 | MSize n; | 99 | MSize n; |
100 | if (L->stacksize > LJ_STACK_MAXEX) /* Overflow while handling overflow? */ | 100 | if (L->stacksize >= LJ_STACK_MAXEX) { |
101 | lj_err_throw(L, LUA_ERRERR); | 101 | /* 4. Throw 'error in error handling' when we are _over_ the limit. */ |
102 | if (L->stacksize > LJ_STACK_MAXEX) | ||
103 | lj_err_throw(L, LUA_ERRERR); /* Does not invoke an error handler. */ | ||
104 | /* 1. We are _at_ the limit after the last growth. */ | ||
105 | if (!L->status) { /* 2. Throw 'stack overflow'. */ | ||
106 | L->status = LUA_ERRRUN; /* Prevent ending here again for pushed msg. */ | ||
107 | lj_err_msg(L, LJ_ERR_STKOV); /* May invoke an error handler. */ | ||
108 | } | ||
109 | /* 3. Add space (over the limit) for pushed message and error handler. */ | ||
110 | } | ||
102 | n = L->stacksize + need; | 111 | n = L->stacksize + need; |
103 | if (n > LJ_STACK_MAX) { | 112 | if (n > LJ_STACK_MAX) { |
104 | n += 2*LUA_MINSTACK; | 113 | n += 2*LUA_MINSTACK; |
@@ -108,8 +117,6 @@ void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need) | |||
108 | n = LJ_STACK_MAX; | 117 | n = LJ_STACK_MAX; |
109 | } | 118 | } |
110 | resizestack(L, n); | 119 | resizestack(L, n); |
111 | if (L->stacksize >= LJ_STACK_MAXEX) | ||
112 | lj_err_msg(L, LJ_ERR_STKOV); | ||
113 | } | 120 | } |
114 | 121 | ||
115 | void LJ_FASTCALL lj_state_growstack1(lua_State *L) | 122 | void LJ_FASTCALL lj_state_growstack1(lua_State *L) |