8000 [3.13] gh-126018: Avoid aborting due to unnecessary assert in `sys.au… · python/cpython@e4157f0 · GitHub
[go: up one dir, main page]

Skip to content

Commit e4157f0

Browse files
miss-islingtondevdanzinpicnixzJelleZijlstra
authored
[3.13] gh-126018: Avoid aborting due to unnecessary assert in sys.audit (GH-126020) (#126042)
(cherry picked from commit 80eec52) Co-authored-by: devdanzin <74280297+devdanzin@users.noreply.github.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent 9e37bfa commit e4157f0

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

Lib/test/audit-tests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,17 @@ def hook(event, args):
567567
_winapi.CreateNamedPipe(pipe_name, _winapi.PIPE_ACCESS_DUPLEX, 8, 2, 0, 0, 0, 0)
568568

569569

570+
def test_assert_unicode():
571+
import sys
572+
sys.addaudithook(lambda *args: None)
573+
try:
574+
sys.audit(9)
575+
except TypeError:
576+
pass
577+
else:
578+
raise RuntimeError("Expected sys.audit(9) to fail.")
579+
580+
570581
if __name__ == "__main__":
571582
from test.support import suppress_msvcrt_asserts
572583

Lib/test/test_audit.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,5 +307,12 @@ def test_winapi_createnamedpipe(self):
307307

308308
self.assertEqual(actual, expected)
309309

310+
def test_assert_unicode(self):
311+
# See gh-126018
312+
returncode, _, stderr = self.run_python("test_assert_unicode")
313+
if returncode:
314+
self.fail(stderr)
315+
316+
310317
if __name__ == "__main__":
311318
unittest.main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a crash in :func:`sys.audit` when passing a non-string as first argument
2+
and Python was compiled in debug mode.

Python/sysmodule.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,6 @@ sys_audit(PyObject *self, PyObject *const *args, Py_ssize_t argc)
518518
}
519519

520520
assert(args[0] != NULL);
521-
assert(PyUnicode_Check(args[0]));
522521

523522
if (!should_audit(tstate->interp)) {
524523
Py_RETURN_NONE;

0 commit comments

Comments
 (0)
0