Skip to content

gh-146065: Fix NULL dereference in FutureIter_am_send#146304

Open
VanshAgarwal24036 wants to merge 5 commits intopython:mainfrom
VanshAgarwal24036:gh-146065-fix-futureiter-null-deref
Open

gh-146065: Fix NULL dereference in FutureIter_am_send#146304
VanshAgarwal24036 wants to merge 5 commits intopython:mainfrom
VanshAgarwal24036:gh-146065-fix-futureiter-null-deref

Conversation

@VanshAgarwal24036
Copy link
Contributor

@VanshAgarwal24036 VanshAgarwal24036 commented Mar 22, 2026

After throw() or close(), it->future can be NULL. A subsequent send() call would dereference it and crash. This adds a NULL check and raises StopIteration instead.

Comment on lines +764 to +767
try:
it.throw(RuntimeError)
except RuntimeError:
pass
Copy link
Member

Choose a reason for hiding this comment

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

Why do we silently suppress this exception here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The RuntimeError is intentionally triggered to clear it->future via FutureIter_throw().

Copy link
Member

@picnixz picnixz Mar 22, 2026

Choose a reason for hiding this comment

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

Then do not suppress it but eagerly catch it with assertRaises.

def test_futureiter_send_after_throw_no_crash(self):
async def run_test():
loop = asyncio.get_event_loop()
fut = loop.create_future()
Copy link
Member

Choose a reason for hiding this comment

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

Alos I would suggest you use the _new_future() helper

Copy link
Member

Choose a reason for hiding this comment

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

i.e I do not think you need a wrapper and asyncio.run()

@bedevere-app
Copy link

bedevere-app bot commented Mar 22, 2026

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@VanshAgarwal24036
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-app
Copy link

bedevere-app bot commented Mar 22, 2026

Thanks for making the requested changes!

@picnixz: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from picnixz March 22, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants