]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.8] gh-87604: Avoid publishing list of active per-interpreter audit hooks via the...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 21 Nov 2022 21:06:01 +0000 (13:06 -0800)
committerGitHub <noreply@github.com>
Mon, 21 Nov 2022 21:06:01 +0000 (22:06 +0100)
(cherry picked from commit 7b98207aa46bd637d07a7c4a84e998726b74acde)

Co-authored-by: Steve Dower <steve.dower@python.org>
Lib/test/audit-tests.py
Lib/test/test_audit.py
Misc/NEWS.d/next/Security/2022-11-11-12-50-28.gh-issue-87604.OtwH5L.rst [new file with mode: 0644]
Python/sysmodule.c

index 8e66594e52429b623eb8f070f861e0b2bb5e816f..45cd0d12c6509f4b0c6e906e6188b9d8ca57fe29 100644 (file)
@@ -341,6 +341,17 @@ def test_gc():
     gc.get_referents(y)
 
 
+def test_not_in_gc():
+    import gc
+
+    hook = lambda *a: None
+    sys.addaudithook(hook)
+
+    for o in gc.get_objects():
+        if isinstance(o, list):
+            assert hook not in o
+
+
 if __name__ == "__main__":
     from test.support import suppress_msvcrt_asserts
 
index a9ac6fee446f872c8bce4dd49ede664557a761e2..fe3d0e0eaea51f63cf12772b6dea8485c6506e6e 100644 (file)
@@ -127,6 +127,11 @@ class AuditTest(unittest.TestCase):
             ["gc.get_objects", "gc.get_referrers", "gc.get_referents"]
         )
 
+    def test_not_in_gc(self):
+        returncode, _, stderr = self.run_python("test_not_in_gc")
+        if returncode:
+            self.fail(stderr)
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/Misc/NEWS.d/next/Security/2022-11-11-12-50-28.gh-issue-87604.OtwH5L.rst b/Misc/NEWS.d/next/Security/2022-11-11-12-50-28.gh-issue-87604.OtwH5L.rst
new file mode 100644 (file)
index 0000000..c931409
--- /dev/null
@@ -0,0 +1,2 @@
+Avoid publishing list of active per-interpreter audit hooks via the
+:mod:`gc` module
index ffda71446712cc34c8526196896a37e310b31862..eb3245a33298cd2742e000d8ce2107c30b10dc9f 100644 (file)
@@ -356,6 +356,8 @@ sys_addaudithook_impl(PyObject *module, PyObject *hook)
         if (is->audit_hooks == NULL) {
             return NULL;
         }
+        /* Avoid having our list of hooks show up in the GC module */
+        PyObject_GC_UnTrack(is->audit_hooks);
     }
 
     if (PyList_Append(is->audit_hooks, hook) < 0) {