Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-126018: Avoid aborting due to unnecessary assert in sys.audit #126020

Merged
merged 7 commits into from
Oct 27, 2024
9 changes: 9 additions & 0 deletions Lib/test/audit-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,15 @@ def hook(event, args):
_winapi.CreateNamedPipe(pipe_name, _winapi.PIPE_ACCESS_DUPLEX, 8, 2, 0, 0, 0, 0)


def test_assert_unicode():
import sys
sys.addaudithook(lambda *args: None)
try:
sys.audit(9)
except TypeError:
pass
devdanzin marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == "__main__":
from test.support import suppress_msvcrt_asserts

Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,5 +307,12 @@ def test_winapi_createnamedpipe(self):

self.assertEqual(actual, expected)

def test_assert_unicode(self):
# See gh-126018
returncode, _, stderr = self.run_python("test_assert_unicode")
if returncode:
self.fail(stderr)


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a crash in :func:`sys.audit` when passing a non-string as first argument.
devdanzin marked this conversation as resolved.
Show resolved Hide resolved
1 change: 0 additions & 1 deletion Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,6 @@ sys_audit(PyObject *self, PyObject *const *args, Py_ssize_t argc)
}

assert(args[0] != NULL);
assert(PyUnicode_Check(args[0]));

if (!should_audit(tstate->interp)) {
Py_RETURN_NONE;
Expand Down
Loading