https://github.com/python/cpython/commit/2b1b68939b15b913080a3403e3ba18e2a1f520ef
commit: 2b1b68939b15b913080a3403e3ba18e2a1f520ef
branch: main
author: Tian Gao <[email protected]>
committer: gaogaotiantian <[email protected]>
date: 2024-07-15T16:11:02-07:00
summary:

gh-121814: Only check f_trace_opcodes if Python frame exists (#121818)

Co-authored-by: Matt Wozniski <[email protected]>

files:
A Misc/NEWS.d/next/Core and 
Builtins/2024-07-15-20-41-06.gh-issue-121814.oR2ixR.rst
M Python/legacy_tracing.c

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 00000000000000..14666de45f32e3
--- /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 74118030925e3e..1103d999dfaea5 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;

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to