summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-03-14 17:07:53 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-03-14 17:07:53 (GMT)
commitc44f70770bf629469a5a179b643e53dfeca884ad (patch)
tree27e18bf327ba065183dae3a9011d7745e1dacc61
parent371977976595836b553969ad8b1630114f894062 (diff)
downloadcpython-c44f70770bf629469a5a179b643e53dfeca884ad.zip
cpython-c44f70770bf629469a5a179b643e53dfeca884ad.tar.gz
cpython-c44f70770bf629469a5a179b643e53dfeca884ad.tar.bz2
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 ...
-rw-r--r--Modules/posixmodule.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 6e0081d..7e89878 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -3320,12 +3320,22 @@ posix_getcwd(int use_bytes)
Py_BEGIN_ALLOW_THREADS
do {
buflen += chunk;
+#ifdef MS_WINDOWS
+ if (buflen > INT_MAX) {
+ PyErr_NoMemory();
+ break;
+ }
+#endif
tmpbuf = PyMem_RawRealloc(buf, buflen);
if (tmpbuf == NULL)
break;
buf = tmpbuf;
+#ifdef MS_WINDOWS
+ cwd = getcwd(buf, (int)buflen);
+#else
cwd = getcwd(buf, buflen);
+#endif
} while (cwd == NULL && errno == ERANGE);
Py_END_ALLOW_THREADS