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

Commit 93fcc1f

Browse filesBrowse files
authored
GH-97752: Clear the previous member of newly-created generator/coroutine frames (GH-97795)
1 parent d053c47 commit 93fcc1f
Copy full SHA for 93fcc1f

File tree

Expand file treeCollapse file tree

3 files changed

+24
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+24
-0
lines changed

‎Lib/test/test_generators.py

Copy file name to clipboardExpand all lines: Lib/test/test_generators.py
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,25 @@ def __del__(self):
206206
finally:
207207
gc.set_threshold(*thresholds)
208208

209+
def test_ag_frame_f_back(self):
210+
async def f():
211+
yield
212+
ag = f()
213+
self.assertIsNone(ag.ag_frame.f_back)
214+
215+
def test_cr_frame_f_back(self):
216+
async def f():
217+
pass
218+
cr = f()
219+
self.assertIsNone(cr.cr_frame.f_back)
220+
cr.close() # Suppress RuntimeWarning.
221+
222+
def test_gi_frame_f_back(self):
223+
def f():
224+
yield
225+
gi = f()
226+
self.assertIsNone(gi.gi_frame.f_back)
227+
209228

210229

211230
class ExceptionTest(unittest.TestCase):
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix possible data corruption or crashes when accessing the ``f_back`` member
2+
of newly-created generator or coroutine frames.

‎Python/frame.c

Copy file name to clipboardExpand all lines: Python/frame.c
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *dest)
5454
assert(src->stacktop >= src->f_code->co_nlocalsplus);
5555
Py_ssize_t size = ((char*)&src->localsplus[src->stacktop]) - (char *)src;
5656
memcpy(dest, src, size);
57+
// Don't leave a dangling pointer to the old frame when creating generators
58+
// and coroutines:
59+
dest->previous = NULL;
5760
}
5861

5962

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.