summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@python.org>2022-11-14 21:39:18 (GMT)
committerGitHub <noreply@github.com>2022-11-14 21:39:18 (GMT)
commit4e4b13e8f6211abbc0d53056da11357756daa314 (patch)
tree9c6dc6406b23edb249ad3c3d69d1ab138f9edc3f
parent3d9431983a89b14250716c1d227e2ce40b343bdd (diff)
downloadcpython-4e4b13e8f6211abbc0d53056da11357756daa314.zip
cpython-4e4b13e8f6211abbc0d53056da11357756daa314.tar.gz
cpython-4e4b13e8f6211abbc0d53056da11357756daa314.tar.bz2
gh-87604: Avoid publishing list of active per-interpreter audit hooks via the gc module (GH-99373)
-rw-r--r--Lib/test/audit-tests.py11
-rw-r--r--Lib/test/test_audit.py5
-rw-r--r--Misc/NEWS.d/next/Security/2022-11-11-12-50-28.gh-issue-87604.OtwH5L.rst2
-rw-r--r--Python/sysmodule.c2
4 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/audit-tests.py b/Lib/test/audit-tests.py
index 4abf33d..a411072 100644
--- a/Lib/test/audit-tests.py
+++ b/Lib/test/audit-tests.py
@@ -450,6 +450,17 @@ def test_syslog():
syslog.closelog()
+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
diff --git a/Lib/test/test_audit.py b/Lib/test/test_audit.py
index 50f78f2..e8d560a 100644
--- a/Lib/test/test_audit.py
+++ b/Lib/test/test_audit.py
@@ -222,6 +222,11 @@ class AuditTest(unittest.TestCase):
('syslog.closelog', '', '')]
)
+ 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
index 0000000..c931409
--- /dev/null
+++ b/Misc/NEWS.d/next/Security/2022-11-11-12-50-28.gh-issue-87604.OtwH5L.rst
@@ -0,0 +1,2 @@
+Avoid publishing list of active per-interpreter audit hooks via the
+:mod:`gc` module
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 1090b12..6f0a126 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -431,6 +431,8 @@ sys_addaudithook_impl(PyObject *module, PyObject *hook)
if (interp->audit_hooks == NULL) {
return NULL;
}
+ /* Avoid having our list of hooks show up in the GC module */
+ PyObject_GC_UnTrack(interp->audit_hooks);
}
if (PyList_Append(interp->audit_hooks, hook) < 0) {