]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-96754: Check whether the interpreter frame is complete before creating frame objec...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 13 Sep 2022 10:56:27 +0000 (03:56 -0700)
committerGitHub <noreply@github.com>
Tue, 13 Sep 2022 10:56:27 +0000 (11:56 +0100)
(cherry picked from commit 12c5f328d2479ac3432df5e266adc4e59adeabfe)

Co-authored-by: Mark Shannon <mark@hotpy.org>
Co-authored-by: Mark Shannon <mark@hotpy.org>
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 66fa2eabbdc91a8e04f03e205d407486bf88c567..a5dfacf4f5ca04cd804a1dde91a4ca8e866fe8a6 100644 (file)
@@ -5747,9 +5747,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 12ebbe33cb8aa501a09f69ba94a993a31d7b44be..425065322ebd429d24325eed33f59f21332238a9 100644 (file)
@@ -1391,6 +1391,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;
             }