diff options
author | Mark Shannon <mark@hotpy.org> | 2022-07-01 10:08:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-01 10:08:20 (GMT) |
commit | 544531de23d69f5b23883794fc7bb23a958a0fcb (patch) | |
tree | ad88c0a6543127cd89027843ab441aa29dbdbc75 /Python | |
parent | 1df9449db24f16c9c96bdd7dc283a5062bca68e6 (diff) | |
download | cpython-544531de23d69f5b23883794fc7bb23a958a0fcb.zip cpython-544531de23d69f5b23883794fc7bb23a958a0fcb.tar.gz cpython-544531de23d69f5b23883794fc7bb23a958a0fcb.tar.bz2 |
GH-94262: Don't create frame objects for frames that aren't yet complete. (GH-94371)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/frame.c | 8 | ||||
-rw-r--r-- | Python/sysmodule.c | 14 |
2 files changed, 17 insertions, 5 deletions
diff --git a/Python/frame.c b/Python/frame.c index 206ecab..7c6705e 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -68,9 +68,13 @@ take_ownership(PyFrameObject *f, _PyInterpreterFrame *frame) f->f_frame = frame; frame->owner = FRAME_OWNED_BY_FRAME_OBJECT; assert(f->f_back == NULL); - if (frame->previous != NULL) { + _PyInterpreterFrame *prev = frame->previous; + while (prev && _PyFrame_IsIncomplete(prev)) { + prev = prev->previous; + } + if (prev) { /* Link PyFrameObjects.f_back and remove link through _PyInterpreterFrame.previous */ - PyFrameObject *back = _PyFrame_GetFrameObject(frame->previous); + PyFrameObject *back = _PyFrame_GetFrameObject(prev); if (back == NULL) { /* Memory error here. */ assert(PyErr_ExceptionMatches(PyExc_MemoryError)); diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 444042f..9312007 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1776,9 +1776,17 @@ sys__getframe_impl(PyObject *module, int depth) return NULL; } - while (depth > 0 && frame != NULL) { - frame = frame->previous; - --depth; + if (frame != NULL) { + while (depth > 0) { + frame = frame->previous; + if (frame == NULL) { + break; + } + if (_PyFrame_IsIncomplete(frame)) { + continue; + } + --depth; + } } if (frame == NULL) { _PyErr_SetString(tstate, PyExc_ValueError, |