Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 91b4fbd

Browse files
committed
Restore Saved_State/Halt_State when a longjmp happens
this fixes CC#2190, which is illustrated by: attempt [; this sets Saved_State catch/quit [ ;this calls Try_Block_Halt and sets Halt_State print x ; this causes an error, and calls ;"longjmp(*State_State)", which invalidates ; Halt_State above. ] ] load %./ ;Just tries to fill up the C stack and messes up "Halt_State". halt ; Jumps to the invalid "Halt_State", and crashes or catch/quit [ ;sets Halt_State attempt [ ;sets Saved_State quit ; jumps to Halt_State, and invalidates "Saved_State" ] ] print x ; Causes a jump to the invalid "Saved_State"
1 parent 6309450 commit 91b4fbd

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/core/c-do.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,9 +1070,12 @@ x*/ static REBINT Do_Args_Light(REBVAL *func, REBVAL *path, REBSER *block, REBCN
10701070
{
10711071
REBOL_STATE state;
10721072
REBVAL *tos;
1073+
jmp_buf *Last_Halt_State = Halt_State;
10731074

10741075
PUSH_STATE(state, Saved_State);
10751076
if (SET_JUMP(state)) {
1077+
/* Halt_State might become invalid, restore the one above */
1078+
Halt_State = Last_Halt_State;
10761079
POP_STATE(state, Saved_State);
10771080
Catch_Error(DS_NEXT); // Stores error value here
10781081
return TRUE;
@@ -1733,6 +1736,7 @@ x*/ static REBINT Do_Args_Light(REBVAL *func, REBVAL *path, REBSER *block, REBCN
17331736
{
17341737
REBOL_STATE state;
17351738
REBVAL *val;
1739+
jmp_buf *Last_Saved_State = Saved_State;
17361740
// static D = 0;
17371741
// int depth = D++;
17381742

@@ -1741,6 +1745,8 @@ x*/ static REBINT Do_Args_Light(REBVAL *func, REBVAL *path, REBSER *block, REBCN
17411745
PUSH_STATE(state, Halt_State);
17421746
if (SET_JUMP(state)) {
17431747
// Debug_Fmt("Throw Halt %d", depth);
1748+
/* Saved_State might become invalid, restore the one above */
1749+
Saved_State = Last_Saved_State;
17441750
POP_STATE(state, Halt_State);
17451751
Catch_Error(DS_NEXT); // Stores error value here
17461752
return TRUE;

0 commit comments

Comments
 (0)