mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
GH-96754: Check whether the interpreter frame is complete before creating frame object. (GH-96776) (#96787)
(cherry picked from commit 12c5f328d2
)
Co-authored-by: Mark Shannon <mark@hotpy.org>
Co-authored-by: Mark Shannon <mark@hotpy.org>
This commit is contained in:
parent
8238fa91c1
commit
c4cf745c72
4 changed files with 14 additions and 3 deletions
|
@ -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.
|
|
@ -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)) {
|
||||
|
|
|
@ -5747,10 +5747,12 @@ error:
|
|||
#endif
|
||||
|
||||
/* Log traceback info. */
|
||||
if (!_PyFrame_IsIncomplete(frame)) {
|
||||
PyFrameObject *f = _PyFrame_GetFrameObject(frame);
|
||||
if (f != NULL) {
|
||||
PyTraceBack_Here(f);
|
||||
}
|
||||
}
|
||||
|
||||
if (tstate->c_tracefunc != NULL) {
|
||||
/* Make sure state is set to FRAME_UNWINDING for tracing */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue