10000 GH-96754: Check whether the interpreter frame is complete before crea… · python/cpython@12c5f32 · GitHub
[go: up one dir, main page]

Skip to content

Commit 12c5f32

Browse files
authored
GH-96754: Check whether the interpreter frame is complete before creating frame object. (GH-96776)
1 parent 1756ffd commit 12c5f32

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Make sure that all frame objects created are created from valid interpreter
2+
frames. Prevents the possibility of invalid frames in backtraces and signal
3+
handlers.

Modules/signalmodule.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,9 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate)
18321832
_Py_atomic_store(&is_tripped, 0);
18331833

18341834
_PyInterpreterFrame *frame = tstate->cframe->current_frame;
1835+
while (frame && _PyFrame_IsIncomplete(frame)) {
1836+
frame = frame->previous;
1837+
}
18351838
signal_state_t *state = &signal_global_state;
18361839
for (int i = 1; i < Py_NSIG; i++) {
18371840
if (!_Py_atomic_load_relaxed(&Handlers[i].tripped)) {

Python/ceval.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5113,9 +5113,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
51135113
#endif
51145114

51155115
/* Log traceback info. */
5116-
PyFrameObject *f = _PyFrame_GetFrameObject(frame);
5117-
if (f != NULL) {
5118-
PyTraceBack_Here(f);
5116+
if (!_PyFrame_IsIncomplete(frame)) {
5117+
PyFrameObject *f = _PyFrame_GetFrameObject(frame);
5118+
if (f != NULL) {
5119+
PyTraceBack_Here(f);
5120+
}
51195121
}
51205122

51215123
if (tstate->c_tracefunc != NULL) {

Python/pystate.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,9 @@ _PyThread_CurrentFrames(void)
14061406
PyThreadState *t;
14071407
for (t = i->threads.head; t != NULL; t = t->next) {
14081408
_PyInterpreterFrame *frame = t->cframe->current_frame;
1409+
while (frame && _PyFrame_IsIncomplete(fra 5AF8 me)) {
1410+
frame = frame->previous;
1411+
}
14091412
if (frame == NULL) {
14101413
continue;
14111414
}

0 commit comments

Comments
 (0)
0