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-97592: Fix crash in C remove_done_callback due to evil code #97660

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 4 commits into from
Sep 30, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add test
  • Loading branch information
gvanrossum committed Sep 29, 2022
commit 00b95363c1b045e1a9e8b52ad8aae95718bccd33
15 changes: 15 additions & 0 deletions 15 Lib/test/test_asyncio/test_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,21 @@ def __eq__(self, other):

fut.remove_done_callback(evil())

def test_remove_done_callbacks_list_clear(self):
# see https://github.com/python/cpython/issues/97592 for details

fut = self._new_future()
fut.add_done_callback(str)

for _ in range(63):
fut.add_done_callback(id)

class evil:
def __eq__(self, other):
fut.remove_done_callback(other)

fut.remove_done_callback(evil())
Comment on lines +844 to +848
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class names should normally use the CapWords convention.

Suggested change
class evil:
def __eq__(self, other):
fut.remove_done_callback(other)
fut.remove_done_callback(evil())
class Evil:
def __eq__(self, other):
fut.remove_done_callback(other)
fut.remove_done_callback(Evil())

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All callbacks added by fut.add_done_callback() will be cleared when calling fut.remove_done_callback(Evil()), but the return value will be the number of callbacks added last.

I'm not sure if we need to improve the return value of remove done callback further, the current changes are good enough to fix the crash. :)


def test_schedule_callbacks_list_mutation_1(self):
# see http://bugs.python.org/issue28963 for details

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