Skip to content

PyUnstable_AtExit isn't well tested and undocumented #127791

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

Closed
ZeroIntensity opened this issue Dec 10, 2024 · 2 comments
Closed

PyUnstable_AtExit isn't well tested and undocumented #127791

ZeroIntensity opened this issue Dec 10, 2024 · 2 comments
Assignees
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes topic-C-API type-bug An unexpected behavior, bug, or error

Comments

@ZeroIntensity
Copy link
Member

ZeroIntensity commented Dec 10, 2024

Bug report

Bug description:

While working on #126908, @vstinner noted that this part of PyUnstable_AtExit looks wrong:

else {
state->last_ll_callback->next = callback;
}

This will result in loss of callbacks after one has been stored, because the second-to-last one is always overwritten. Noted in gh-118915, PyUnstable_AtExit is also undocumented. I'll work on fixing both.

CPython versions tested on:

3.13, 3.14, CPython main branch

Operating systems tested on:

Linux

Linked PRs

@ZeroIntensity ZeroIntensity added type-bug An unexpected behavior, bug, or error topic-C-API 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Dec 10, 2024
@ZeroIntensity ZeroIntensity self-assigned this Dec 10, 2024
@disconnect3d
Copy link
Contributor

This will result in loss of callbacks after one has been stored (...)

Hi, just out of curiosity: what does this exactly mean? Is this a memory leak or an UAF?

@ZeroIntensity
Copy link
Member Author

Memory leak, I think? The next pointer in the linked list is overwritten.

ZeroIntensity added a commit to ZeroIntensity/cpython that referenced this issue Dec 11, 2024
…ythonGH-127793)

(cherry picked from commit d5d84c3)

Co-authored-by: Peter Bierma <[email protected]>
vstinner pushed a commit that referenced this issue Dec 11, 2024
) (#127819)

* Fix merge conflicts.

* [3.13] gh-127791: Fix, document, and test `PyUnstable_AtExit` (GH-127793)
(cherry picked from commit d5d84c3)

Co-authored-by: Peter Bierma <[email protected]>
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes topic-C-API type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants