From 452407ba77f88ed2128ea2eec8bfdc963ef961d7 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Sat, 27 Jun 2026 10:07:09 +0100 Subject: [PATCH] Fix UB in `INSTRUMENTED_JUMP` --- .../2026-06-27-10-05-12.gh-issue-152375.L-ZBk6.rst | 2 ++ Python/ceval_macros.h | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-06-27-10-05-12.gh-issue-152375.L-ZBk6.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-27-10-05-12.gh-issue-152375.L-ZBk6.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-27-10-05-12.gh-issue-152375.L-ZBk6.rst new file mode 100644 index 000000000000000..db6ae3060d8328f --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-27-10-05-12.gh-issue-152375.L-ZBk6.rst @@ -0,0 +1,2 @@ +Fix undefined behaviour when a :mod:`sys.monitoring` callback raised an +exception while the program was following a branch or loop. diff --git a/Python/ceval_macros.h b/Python/ceval_macros.h index 0de4477426af358..b13884bf8214d41 100644 --- a/Python/ceval_macros.h +++ b/Python/ceval_macros.h @@ -389,14 +389,15 @@ static void dtrace_function_return(_PyInterpreterFrame *); // for an exception handler, displaying the traceback, and so on #define INSTRUMENTED_JUMP(src, dest, event) \ do { \ + _Py_CODEUNIT *_dest = (dest); \ if (tstate->tracing) {\ - next_instr = dest; \ + next_instr = _dest; \ } else { \ _PyFrame_SetStackPointer(frame, stack_pointer); \ - next_instr = _Py_call_instrumentation_jump(this_instr, tstate, event, frame, src, dest); \ + next_instr = _Py_call_instrumentation_jump(this_instr, tstate, event, frame, src, _dest); \ stack_pointer = _PyFrame_GetStackPointer(frame); \ if (next_instr == NULL) { \ - next_instr = (dest)+1; \ + next_instr = _dest + 1; \ JUMP_TO_LABEL(error); \ } \ } \