diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-08-11 09:58:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-11 09:58:58 (GMT) |
commit | 81d3afae1ae89a302866fb0cd12dc9f722e8aa4c (patch) | |
tree | 76236b14821006e1ec9d227161d16c40139f4846 | |
parent | ddca26188d7828ecb762213f4b9c15d44b6048cc (diff) | |
download | cpython-81d3afae1ae89a302866fb0cd12dc9f722e8aa4c.zip cpython-81d3afae1ae89a302866fb0cd12dc9f722e8aa4c.tar.gz cpython-81d3afae1ae89a302866fb0cd12dc9f722e8aa4c.tar.bz2 |
[3.12] GH-107774: Add missing audit event for PEP 669 (GH-107775) (#107839)
GH-107774: Add missing audit event for PEP 669 (GH-107775)
(cherry picked from commit 494e3d4436774a5ac1a569a635b8c5c881ef1c0c)
Co-authored-by: Mark Shannon <mark@hotpy.org>
-rw-r--r-- | Lib/test/audit-tests.py | 11 | ||||
-rw-r--r-- | Lib/test/test_audit.py | 13 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Security/2023-08-05-03-51-05.gh-issue-107774.VPjaTR.rst | 3 | ||||
-rw-r--r-- | Python/instrumentation.c | 3 |
4 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/audit-tests.py b/Lib/test/audit-tests.py index 0edc9d9..9504829 100644 --- a/Lib/test/audit-tests.py +++ b/Lib/test/audit-tests.py @@ -514,6 +514,17 @@ def test_not_in_gc(): assert hook not in o +def test_sys_monitoring_register_callback(): + import sys + + def hook(event, args): + if event.startswith("sys.monitoring"): + print(event, args) + + sys.addaudithook(hook) + sys.monitoring.register_callback(1, 1, None) + + 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 0b69864..b12ffa5 100644 --- a/Lib/test/test_audit.py +++ b/Lib/test/test_audit.py @@ -257,5 +257,18 @@ class AuditTest(unittest.TestCase): self.fail(stderr) + def test_sys_monitoring_register_callback(self): + returncode, events, stderr = self.run_python("test_sys_monitoring_register_callback") + if returncode: + self.fail(stderr) + + if support.verbose: + print(*events, sep='\n') + actual = [(ev[0], ev[2]) for ev in events] + expected = [("sys.monitoring.register_callback", "(None,)")] + + self.assertEqual(actual, expected) + + if __name__ == "__main__": unittest.main() diff --git a/Misc/NEWS.d/next/Security/2023-08-05-03-51-05.gh-issue-107774.VPjaTR.rst b/Misc/NEWS.d/next/Security/2023-08-05-03-51-05.gh-issue-107774.VPjaTR.rst new file mode 100644 index 0000000..b89b50c --- /dev/null +++ b/Misc/NEWS.d/next/Security/2023-08-05-03-51-05.gh-issue-107774.VPjaTR.rst @@ -0,0 +1,3 @@ +PEP 669 specifies that ``sys.monitoring.register_callback`` will generate an +audit event. Pre-releases of Python 3.12 did not generate the audit event. +This is now fixed. diff --git a/Python/instrumentation.c b/Python/instrumentation.c index 8714324..a5b10ae 100644 --- a/Python/instrumentation.c +++ b/Python/instrumentation.c @@ -1858,6 +1858,9 @@ monitoring_register_callback_impl(PyObject *module, int tool_id, int event, PyErr_Format(PyExc_ValueError, "invalid event %d", event); return NULL; } + if (PySys_Audit("sys.monitoring.register_callback", "O", func) < 0) { + return NULL; + } if (func == Py_None) { func = NULL; } |