bpo-37412: Fix os.getcwd() for long path on Windows (GH-14424)

* Fix test for integer overflow.
* Add an unit test.
This commit is contained in:
Victor Stinner 2019-06-28 18:01:59 +02:00 committed by GitHub
parent 3029035ef3
commit ec3e20a2d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 1 deletions

View file

@ -3334,7 +3334,7 @@ posix_getcwd(int use_bytes)
terminating \0. If the buffer is too small, len includes
the space needed for the terminator. */
if (len >= Py_ARRAY_LENGTH(wbuf)) {
if (len >= PY_SSIZE_T_MAX / sizeof(wchar_t)) {
if (len <= PY_SSIZE_T_MAX / sizeof(wchar_t)) {
wbuf2 = PyMem_RawMalloc(len * sizeof(wchar_t));
}
else {