https://github.com/python/cpython/commit/626394e0a38bdf7734567f00a09837f09e653bff
commit: 626394e0a38bdf7734567f00a09837f09e653bff
branch: main
author: Jelle Zijlstra <[email protected]>
committer: JelleZijlstra <[email protected]>
date: 2026-10-19T19:30:32-07:00
summary:
gh-159739: Handle interpreter configuration encoding errors (#159747)
Propagate UTF-8 conversion errors before copying a string configuration
value.
files:
A
Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-19-33-35.gh-issue-159739.a8775b.rst
M Python/interpconfig.c
diff --git
a/Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-19-33-35.gh-issue-159739.a8775b.rst
b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-19-33-35.gh-issue-159739.a8775b.rst
new file mode 100644
index 00000000000000..73c2e9bd5d36b9
--- /dev/null
+++
b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-19-19-33-35.gh-issue-159739.a8775b.rst
@@ -0,0 +1,2 @@
+Avoid a crash when an interpreter configuration string cannot be encoded as
+UTF-8.
diff --git a/Python/interpconfig.c b/Python/interpconfig.c
index a37bd3f5b23a01..9ff28f88134318 100644
--- a/Python/interpconfig.c
+++ b/Python/interpconfig.c
@@ -133,7 +133,12 @@ _config_dict_copy_str(PyObject *dict, const char *name,
config_dict_invalid_type(name);
return -1;
}
- strncpy(buf, PyUnicode_AsUTF8(item), bufsize-1);
+ const char *str = PyUnicode_AsUTF8(item);
+ if (str == NULL) {
+ Py_DECREF(item);
+ return -1;
+ }
+ strncpy(buf, str, bufsize-1);
buf[bufsize-1] = '\0';
Py_DECREF(item);
return 0;
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]