]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-32869: Fix incorrect dst buffer size for MultiByteToWideChar (#5739)
authorAlexey Izbyshev <izbyshev@users.noreply.github.com>
Sun, 18 Feb 2018 17:57:24 +0000 (20:57 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 18 Feb 2018 17:57:24 +0000 (19:57 +0200)
This function expects the destination buffer size to be given
in wide characters, not bytes.

Python/fileutils.c

index 3cf8b7a8b69d73d46a92d2e1ae2c15a878507671..32aeea4f10374b6353a4186bf09ea91dcce656b8 100644 (file)
@@ -1289,7 +1289,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;