Skip to content

Commit be68d9a

Browse files
[3.14] gh-152375: Fix undefined behaviour in the INSTRUMENTED_JUMP macro (GH-152376) (#152567)
(cherry picked from commit cdec9ac) Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent 80a10a2 commit be68d9a

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix undefined behaviour when a :mod:`sys.monitoring` callback raised an
2+
exception while the program was following a branch or loop.

Python/ceval_macros.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,15 @@ GETITEM(PyObject *v, Py_ssize_t i) {
320320
// for an exception handler, displaying the traceback, and so on
321321
#define INSTRUMENTED_JUMP(src, dest, event) \
322322
do { \
323+
_Py_CODEUNIT *_dest = (dest); \
323324
if (tstate->tracing) {\
324-
next_instr = dest; \
325+
next_instr = _dest; \
325326
} else { \
326327
_PyFrame_SetStackPointer(frame, stack_pointer); \
327-
next_instr = _Py_call_instrumentation_jump(this_instr, tstate, event, frame, src, dest); \
328+
next_instr = _Py_call_instrumentation_jump(this_instr, tstate, event, frame, src, _dest); \
328329
stack_pointer = _PyFrame_GetStackPointer(frame); \
329330
if (next_instr == NULL) { \
330-
next_instr = (dest)+1; \
331+
next_instr = _dest + 1; \
331332
JUMP_TO_LABEL(error); \
332333
} \
333334
} \

0 commit comments

Comments
 (0)