Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a crash in :func:`locale.strxfrm` on DragonFly BSD,
whose ``wcsxfrm()`` does not support the zero size.
5 changes: 4 additions & 1 deletion Modules/_localemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ _locale_strxfrm_impl(PyObject *module, PyObject *str)
{
Py_ssize_t n1;
wchar_t *s = NULL, *buf = NULL;
wchar_t dummy[1];
size_t n2;
PyObject *result = NULL;

Expand All @@ -456,7 +457,9 @@ _locale_strxfrm_impl(PyObject *module, PyObject *str)
}

errno = 0;
n2 = wcsxfrm(NULL, s, 0);
/* Query the size with a real one-element buffer: DragonFly BSD's
wcsxfrm() crashes when the destination is NULL or the size is 0. */
n2 = wcsxfrm(dummy, s, 1);
if (errno && errno != ERANGE) {
PyErr_SetFromErrno(PyExc_OSError);
goto exit;
Expand Down
Loading