From 2b1b68939b15b913080a3403e3ba18e2a1f520ef Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Mon, 15 Jul 2024 16:11:02 -0700 Subject: [PATCH] gh-121814: Only check f_trace_opcodes if Python frame exists (#121818) Co-authored-by: Matt Wozniski --- .../2024-07-15-20-41-06.gh-issue-121814.oR2ixR.rst | 1 + Python/legacy_tracing.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-07-15-20-41-06.gh-issue-121814.oR2ixR.rst 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 00000000000..14666de45f3 --- /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 74118030925..1103d999dfa 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;