Skip to content

Commit e89cc13

Browse files
committed
nlr: If DEBUG, guard against recursive nlr_push().
Pushing same NLR record twice would lead to "infinite loop" in nlr_jump (but more realistically, it will crash as soon as NLR record on stack is overwritten).
1 parent 53e5e0f commit e89cc13

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

py/nlr.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,18 @@ void nlr_jump_fail(void *val);
8888
#ifndef DEBUG
8989
#define nlr_raise(val) nlr_jump(val)
9090
#else
91+
#include "mpstate.h"
9192
#define nlr_raise(val) \
9293
do { \
9394
void *_val = val; \
9495
assert(_val != NULL); \
9596
assert(mp_obj_is_exception_instance(_val)); \
9697
nlr_jump(_val); \
9798
} while (0)
99+
100+
#define nlr_push(val) \
101+
assert(MP_STATE_VM(nlr_top) != val),nlr_push(val)
102+
98103
#endif
99104

100105
#endif // __MICROPY_INCLUDED_PY_NLR_H__

0 commit comments

Comments
 (0)