bpo-37412: Fix os.getcwd() for long path on Windows (GH-14424) (GH-14451)
* Fix test for integer overflow.
* Add an unit test.
(cherry picked from commit ec3e20a2d1edddb0558f9d32e2b367904ccdde88)
Co-authored-by: Victor Stinner <vstinner@redhat.com>
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 4301e87..bceee89 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -3333,7 +3333,7 @@
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 {