]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-96754: Check whether the interpreter frame is complete before creating frame objec...
authorMark Shannon <mark@hotpy.org>
Tue, 13 Sep 2022 08:25:16 +0000 (09:25 +0100)
committerGitHub <noreply@github.com>
Tue, 13 Sep 2022 08:25:16 +0000 (09:25 +0100)
Misc/NEWS.d/next/Core and Builtins/2022-09-12-16-58-22.gh-issue-96754.0GRme5.rst [new file with mode: 0644]
Modules/signalmodule.c
Python/ceval.c
Python/pystate.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-09-12-16-58-22.gh-issue-96754.0GRme5.rst b/Misc/NEWS.d/next/Core and Builtins/2022-09-12-16-58-22.gh-issue-96754.0GRme5.rst
new file mode 100644 (file)
index 0000000..beac84e
--- /dev/null
@@ -0,0 +1,3 @@
+Make sure that all frame objects created are created from valid interpreter
+frames. Prevents the possibility of invalid frames in backtraces and signal
+handlers.
index e3b37f179312d405a7596452c697b4999876c0b0..0f30b4da036313e01e9a8488acbdb43ee42a2714 100644 (file)
@@ -1832,6 +1832,9 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate)
     _Py_atomic_store(&is_tripped, 0);
 
     _PyInterpreterFrame *frame = tstate->cframe->current_frame;
+    while (frame && _PyFrame_IsIncomplete(frame)) {
+        frame = frame->previous;
+    }
     signal_state_t *state = &signal_global_state;
     for (int i = 1; i < Py_NSIG; i++) {
         if (!_Py_atomic_load_relaxed(&Handlers[i].tripped)) {
index 20d0e1c50a5f0a6069acba91b68dc83b8a4046f7..091b0eb76407b415336b11d66f29bd4835881998 100644 (file)
@@ -5113,9 +5113,11 @@ error:
 #endif
 
         /* Log traceback info. */
-        PyFrameObject *f = _PyFrame_GetFrameObject(frame);
-        if (f != NULL) {
-            PyTraceBack_Here(f);
+        if (!_PyFrame_IsIncomplete(frame)) {
+            PyFrameObject *f = _PyFrame_GetFrameObject(frame);
+            if (f != NULL) {
+                PyTraceBack_Here(f);
+            }
         }
 
         if (tstate->c_tracefunc != NULL) {
index a0d61d7ebb3be988fbd79a5a54c6a652c473a4b7..23e9d24c591b6303d4d009518b967921bd691893 100644 (file)
@@ -1406,6 +1406,9 @@ _PyThread_CurrentFrames(void)
         PyThreadState *t;
         for (t = i->threads.head; t != NULL; t = t->next) {
             _PyInterpreterFrame *frame = t->cframe->current_frame;
+            while (frame && _PyFrame_IsIncomplete(frame)) {
+                frame = frame->previous;
+            }
             if (frame == NULL) {
                 continue;
             }