From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 16 Jul 2024 17:13:28 +0000 (+0200) Subject: [3.13] gh-121814: Only check f_trace_opcodes if Python frame exists (GH-121818) ... X-Git-Tag: v3.13.0b4~24 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=54db42fe2ca6b6cbbed84499627064367869e6cb;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-121814: Only check f_trace_opcodes if Python frame exists (GH-121818) (#121861) gh-121814: Only check f_trace_opcodes if Python frame exists (GH-121818) (cherry picked from commit 2b1b68939b15b913080a3403e3ba18e2a1f520ef) Co-authored-by: Tian Gao Co-authored-by: Matt Wozniski --- diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-07-15-20-41-06.gh-issue-121814.oR2ixR.rst b/Misc/NEWS.d/next/Core and Builtins/2024-07-15-20-41-06.gh-issue-121814.oR2ixR.rst new file mode 100644 index 000000000000..14666de45f32 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-07-15-20-41-06.gh-issue-121814.oR2ixR.rst @@ -0,0 +1 @@ +Fixed the SegFault when :c:func:`PyEval_SetTrace` is used with no Python frame on stack. diff --git a/Python/legacy_tracing.c b/Python/legacy_tracing.c index 74118030925e..1103d999dfae 100644 --- a/Python/legacy_tracing.c +++ b/Python/legacy_tracing.c @@ -605,7 +605,7 @@ _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg) (1 << PY_MONITORING_EVENT_STOP_ITERATION); PyFrameObject* frame = PyEval_GetFrame(); - if (frame->f_trace_opcodes) { + if (frame && frame->f_trace_opcodes) { int ret = _PyEval_SetOpcodeTrace(frame, true); if (ret != 0) { return ret;