]> granicus.if.org Git - python/commitdiff
bpo-32869: Fix incorrect dst buffer size for MultiByteToWideChar (GH-5739)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 18 Feb 2018 18:58:09 +0000 (10:58 -0800)
committerGitHub <noreply@github.com>
Sun, 18 Feb 2018 18:58:09 +0000 (10:58 -0800)
This function expects the destination buffer size to be given
in wide characters, not bytes.
(cherry picked from commit b3b4a9d3001f1fc7df8efcccdce081de54fa5eab)

Co-authored-by: Alexey Izbyshev <izbyshev@users.noreply.github.com>
Python/fileutils.c

index 899ea8aecac0fbc556c49f085b301ba42a559858..b9638d2df513bee4c3dc4f049a6a8716b536c629 100644 (file)
@@ -1185,7 +1185,8 @@ _Py_fopen_obj(PyObject *path, const char *mode)
     if (wpath == NULL)
         return NULL;
 
-    usize = MultiByteToWideChar(CP_ACP, 0, mode, -1, wmode, sizeof(wmode));
+    usize = MultiByteToWideChar(CP_ACP, 0, mode, -1,
+                                wmode, Py_ARRAY_LENGTH(wmode));
     if (usize == 0) {
         PyErr_SetFromWindowsErr(0);
         return NULL;