]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.9] gh-87604: Avoid publishing list of active per-interpreter audit hooks via the...
authorSteve Dower <steve.dower@python.org>
Mon, 21 Nov 2022 18:13:33 +0000 (18:13 +0000)
committerGitHub <noreply@github.com>
Mon, 21 Nov 2022 18:13:33 +0000 (19:13 +0100)
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 95216bcc48253c453e1ace49402eaf6b691e1b5a..6de636a9e9dc6af32704a7000f8b8a18b078634f 100644 (file)
@@ -368,6 +368,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 387a31229a2f164924639b935b3475c239eaa8cb..e47e5569c2b914129bfe1a459b7ad51bb424dee6 100644 (file)
@@ -132,6 +132,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 8efa850dce6fc38810599e018c73d317254db8e3..a8f2f021c3260a424142600192272b748888f855 100644 (file)
@@ -440,6 +440,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) {