-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-112127: Fix use-after-free in atexit.unregister() #114092
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
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6c8db8a
Fix use-after-free in atexit.unregister()
benjaminJohnson2204 0623581
Merge branch 'main' into gh-112127
benjaminJohnson2204 8e6d5c6
Merge branch 'main' into gh-112127
benjaminJohnson2204 075c49f
Address code review comments in atexit tests
benjaminJohnson2204 5b022fc
Fix linter issue
benjaminJohnson2204 1148d80
Merge branch 'main' into gh-112127
serhiy-storchaka 9056824
Address PR comments
benjaminJohnson2204 0775ca8
Remove trailing whitespace
benjaminJohnson2204 c01d7db
Merge branch 'main' into gh-112127
serhiy-storchaka 143fd96
Fix tests.
serhiy-storchaka 99e35c9
Add a NEWS entry.
serhiy-storchaka 7ec0097
Fix use-after-free issue in atexit.unregister
serhiy-storchaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,6 +135,40 @@ def func(): | |
| finally: | ||
| atexit.unregister(func) | ||
|
|
||
| def test_eq_unregister_clear(self): | ||
| # Issue #112127: callback's __eq__ may call unregister or _clear | ||
| global cnt | ||
| cnt = 0 | ||
| class Func: | ||
| def __init__(self, action, eq_ret_val): | ||
| self.action = action | ||
| self.eq_ret_val = eq_ret_val | ||
|
|
||
| def __call__(self): | ||
| return | ||
|
|
||
| def __eq__(self, o): | ||
| global cnt | ||
| cnt += 1 | ||
benjaminJohnson2204 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if cnt == 1: | ||
| self.action(o) | ||
| return self.eq_ret_val(o) | ||
|
||
|
|
||
| for action, eq_ret_val in ( | ||
benjaminJohnson2204 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (lambda o: atexit.unregister(self), lambda o: NotImplemented), | ||
| (lambda o: atexit.unregister(self), lambda o: True), | ||
| (lambda o: atexit.unregister(o), lambda o: NotImplemented), | ||
| (lambda o: atexit.unregister(o), lambda o: True), | ||
| (lambda o: atexit._clear(), lambda o: NotImplemented), | ||
| (lambda o: atexit._clear(), lambda o: True), | ||
| ): | ||
| cnt = 0 | ||
benjaminJohnson2204 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| f1 = Func(action, eq_ret_val) | ||
| f2 = Func(action, eq_ret_val) | ||
| atexit.register(f1) | ||
| atexit.register(f2) | ||
| atexit._run_exitfuncs() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.