bpo-30708: Check for null characters in PyUnicode_AsWideCharString(). (#2285)

Raise a ValueError if the second argument is NULL and the wchar_t\*
string contains null characters.
This commit is contained in:
Serhiy Storchaka
2017-06-27 16:03:14 +03:00
committed by GitHub
parent 65474b9d7a
commit e613e6add5
6 changed files with 44 additions and 42 deletions

View File

@@ -304,18 +304,11 @@ _io__WindowsConsoleIO___init___impl(winconsoleio *self, PyObject *nameobj,
if (!d)
return -1;
Py_ssize_t length;
name = PyUnicode_AsWideCharString(decodedname, &length);
name = PyUnicode_AsWideCharString(decodedname, NULL);
console_type = _PyIO_get_console_type(decodedname);
Py_CLEAR(decodedname);
if (name == NULL)
return -1;
if (wcslen(name) != length) {
PyMem_Free(name);
PyErr_SetString(PyExc_ValueError, "embedded null character");
return -1;
}
}
s = mode;