Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

GH-97752: Clear the previous member of newly-created generator/coroutine frames #97795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions 19 Lib/test/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,25 @@ def __del__(self):
finally:
gc.set_threshold(*thresholds)

def test_ag_frame_f_back(self):
async def f():
yield
ag = f()
self.assertIsNone(ag.ag_frame.f_back)

def test_cr_frame_f_back(self):
async def f():
pass
cr = f()
self.assertIsNone(cr.cr_frame.f_back)
cr.close() # Suppress RuntimeWarning.

def test_gi_frame_f_back(self):
def f():
yield
gi = f()
self.assertIsNone(gi.gi_frame.f_back)



class ExceptionTest(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix possible data corruption or crashes when accessing the ``f_back`` member
of newly-created generator or coroutine frames.
3 changes: 3 additions & 0 deletions 3 Python/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *dest)
assert(src->stacktop >= src->f_code->co_nlocalsplus);
Py_ssize_t size = ((char*)&src->localsplus[src->stacktop]) - (char *)src;
memcpy(dest, src, size);
// Don't leave a dangling pointer to the old frame when creating generators
// and coroutines:
dest->previous = NULL;
}


Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.