Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c44f707

Browse files
committed
posix_getcwd(): limit to INT_MAX on Windows
It's more to fix a conversion warning during compilation, I don't think that Windows support current working directory larger than 2 GB ...
1 parent 3719779 commit c44f707

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

Modules/posixmodule.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3320,12 +3320,22 @@ posix_getcwd(int use_bytes)
33203320
Py_BEGIN_ALLOW_THREADS
33213321
do {
33223322
buflen += chunk;
3323+
#ifdef MS_WINDOWS
3324+
if (buflen > INT_MAX) {
3325+
PyErr_NoMemory();
3326+
break;
3327+
}
3328+
#endif
33233329
tmpbuf = PyMem_RawRealloc(buf, buflen);
33243330
if (tmpbuf == NULL)
33253331
break;
33263332

33273333
buf = tmpbuf;
3334+
#ifdef MS_WINDOWS
3335+
cwd = getcwd(buf, (int)buflen);
3336+
#else
33283337
cwd = getcwd(buf, buflen);
3338+
#endif
33293339
} while (cwd == NULL && errno == ERANGE);
33303340
Py_END_ALLOW_THREADS
33313341

0 commit comments

Comments
 (0)