mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
[3.14] gh-112127: Fix possible use-after-free in atexit.unregister() (GH-114092) (#142878)
gh-112127: Fix possible use-after-free in atexit.unregister() (GH-114092)
(cherry picked from commit 2b466c47c3)
Co-authored-by: Benjamin Johnson <ben332004@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
06137178b0
commit
8c92d665ee
4 changed files with 18 additions and 1 deletions
|
|
@ -135,6 +135,19 @@ def func():
|
|||
finally:
|
||||
atexit.unregister(func)
|
||||
|
||||
def test_eq_unregister_clear(self):
|
||||
# Issue #112127: callback's __eq__ may call unregister or _clear
|
||||
class Evil:
|
||||
def __eq__(self, other):
|
||||
action(other)
|
||||
return NotImplemented
|
||||
|
||||
for action in atexit.unregister, lambda o: atexit._clear():
|
||||
with self.subTest(action=action):
|
||||
atexit.register(lambda: None)
|
||||
atexit.unregister(Evil())
|
||||
atexit._clear()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue