Skip to content

Commit

Permalink
GH-96754: Check whether the interpreter frame is complete before crea…
Browse files Browse the repository at this point in the history
…ting frame object. (GH-96776)
  • Loading branch information
markshannon authored Sep 13, 2022
1 parent 1756ffd commit 12c5f32
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions Modules/signalmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
8 changes: 5 additions & 3 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -5113,9 +5113,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
#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) {
Expand Down
3 changes: 3 additions & 0 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 12c5f32

Please sign in to comment.