Skip to content

Commit 9e9531f

Browse files
authored
Fix atexit on Python 3 (#1852)
* Fix atexit on Python 3 `sys.exitfunc` was removed in Python 3, meaning that any handlers registered with the `pwnlib/atexit.py` module wouldn't run. This PR reigsters the handlers with the stdlib atexit. * Update changelog
1 parent 3d5ca37 commit 9e9531f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ The table below shows which release corresponds to each branch, and what date th
151151

152152
## 4.3.1
153153

154+
- [#1852][1852] Fix `atexit` on Python 3
154155
- [#1732][1732] Fix shellcraft SSTI vulnerability (first major pwntools vuln!)
155156

156157
[1732]: https://github.com/Gallopsled/pwntools/pull/1732

pwnlib/atexit.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import sys
1414
import threading
1515
import traceback
16+
import atexit as std_atexit
1617

1718
from pwnlib.context import context
1819

@@ -95,4 +96,8 @@ def _run_handlers():
9596
if hasattr(sys, "exitfunc"):
9697
register(sys.exitfunc)
9798

98-
sys.exitfunc = _run_handlers
99+
if sys.version_info[0] < 3:
100+
sys.exitfunc = _run_handlers
101+
else:
102+
std_atexit.register(_run_handlers)
103+

0 commit comments

Comments
 (0)