Skip to content

Commit d456311

Browse files
serhiy-storchakaronaldoussoren
authored andcommitted
pythongh-130567: Fix possible crash in locale.strxfrm() (pythonGH-138940)
On some macOS versions there was an off-by-one error in wcsxfrm() which caused writing past the end of the array if its size was not calculated by running wcsxfrm() first. (cherry picked from commit 5854cf3) Co-authored-by: Serhiy Storchaka <[email protected]> Co-authored-by: Ronald Oussoren <[email protected]>
1 parent 460ad1a commit d456311

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix possible crash in :func:`locale.strxfrm` due to a platform bug on
2+
macOS.

Modules/_localemodule.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,9 @@ _locale_strxfrm_impl(PyObject *module, PyObject *str)
410410

411411
/* assume no change in size, first */
412412
n1 = n1 + 1;
413-
buf = PyMem_New(wchar_t, n1);
413+
/* Yet another +1 is needed to work around a platform bug in wcsxfrm()
414+
* on macOS. See gh-130567. */
415+
buf = PyMem_New(wchar_t, n1+1);
414416
if (!buf) {
415417
PyErr_NoMemory();
416418
goto exit;

0 commit comments

Comments
 (0)