FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.13] gh-112127: Fix possible use-after-free in atexit.unregister() (GH-114092) by serhiy-storchaka · Pull Request #142880 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (1) No extension  (1) All 4 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
13 changes: 13 additions & 0 deletions Lib/test/_test_atexit.py
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
Expand Up @@ -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()
1 change: 1 addition & 0 deletions Misc/ACKS
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
Expand Up @@ -892,6 +892,7 @@ Jim Jewett
Pedro Diaz Jimenez
Orjan Johansen
Fredrik Johansson
Benjamin Johnson
Gregory K. Johnson
Kent Johnson
Michael Johnson
Expand Down
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
@@ -0,0 +1,2 @@
Fix possible use-after-free in :func:`atexit.unregister` when the callback
is unregistered during comparison.
4 changes: 3 additions & 1 deletion Modules/atexitmodule.c
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
Expand Up @@ -287,7 +287,9 @@ atexit_unregister(PyObject *module, PyObject *func)
continue;
}

int eq = PyObject_RichCompareBool(cb->func, func, Py_EQ);
PyObject *to_compare = Py_NewRef(cb->func);
int eq = PyObject_RichCompareBool(to_compare, func, Py_EQ);
Py_DECREF(to_compare);
if (eq < 0) {
return NULL;
}
Expand Down
Loading

Back | FazBrowse Home | New Git URL