Skip to content

Commit 4e4b13e

Browse files
authored
gh-87604: Avoid publishing list of active per-interpreter audit hooks via the gc module (GH-99373)
1 parent 3d94319 commit 4e4b13e

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

Lib/test/audit-tests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,17 @@ def hook(event, args):
450450
syslog.closelog()
451451

452452

453+
def test_not_in_gc():
454+
import gc
455+
456+
hook = lambda *a: None
457+
sys.addaudithook(hook)
458+
459+
for o in gc.get_objects():
460+
if isinstance(o, list):
461+
assert hook not in o
462+
463+
453464
if __name__ == "__main__":
454465
from test.support import suppress_msvcrt_asserts
455466

Lib/test/test_audit.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ def test_syslog(self):
222222
('syslog.closelog', '', '')]
223223
)
224224

225+
def test_not_in_gc(self):
226+
returncode, _, stderr = self.run_python("test_not_in_gc")
227+
if returncode:
228+
self.fail(stderr)
229+
225230

226231
if __name__ == "__main__":
227232
unittest.main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Avoid publishing list of active per-interpreter audit hooks via the
2+
:mod:`gc` module

Python/sysmodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,8 @@ sys_addaudithook_impl(PyObject *module, PyObject *hook)
431431
if (interp->audit_hooks == NULL) {
432432
return NULL;
433433
}
434+
/* Avoid having our list of hooks show up in the GC module */
435+
PyObject_GC_UnTrack(interp->audit_hooks);
434436
}
435437

436438
if (PyList_Append(interp->audit_hooks, hook) < 0) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy