[Python-checkins] cpython (3.2): Correct completely broken os.stat behavior on Windows XP.

brian.curtin python-checkins at python.org
Tue Jun 14 17:06:50 CEST 2011


http://hg.python.org/cpython/rev/1524a60016d0
changeset:   70815:1524a60016d0
branch:      3.2
user:        Brian Curtin <brian at python.org>
date:        Tue Jun 14 09:52:50 2011 -0500
summary:
  Correct completely broken os.stat behavior on Windows XP.

After 1a3e8db28d49, Windows XP could not os.stat at all due to raising
immediately when GetFinalPathNameByHandle wasn't available (pre-Vista).
The proper behavior in that situation is to just not attempt a traversal
rather than outright rejecting.

This change additionally handles a failed malloc by setting the error code
and returning false.

Patch by Hirokazu Yamamoto.

files:
  Modules/posixmodule.c |  21 +++++++++++----------
  1 files changed, 11 insertions(+), 10 deletions(-)


diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1102,6 +1102,11 @@
         return FALSE;
 
     buf = (wchar_t *)malloc((buf_size+1)*sizeof(wchar_t));
+    if (!buf) {
+        SetLastError(ERROR_OUTOFMEMORY);
+        return FALSE;
+    }
+
     result_length = Py_GetFinalPathNameByHandleW(hdl,
                        buf, buf_size, VOLUME_NAME_DOS);
 
@@ -1136,11 +1141,9 @@
     const char *dot;
 
     if(!check_GetFinalPathNameByHandle()) {
-        /* If the OS doesn't have GetFinalPathNameByHandle, return a
-           NotImplementedError. */
-        PyErr_SetString(PyExc_NotImplementedError,
-            "GetFinalPathNameByHandle not available on this platform");
-        return -1;
+        /* If the OS doesn't have GetFinalPathNameByHandle, don't
+           traverse reparse point. */
+        traverse = FALSE;
     }
 
     hFile = CreateFileA(
@@ -1234,11 +1237,9 @@
     const wchar_t *dot;
 
     if(!check_GetFinalPathNameByHandle()) {
-        /* If the OS doesn't have GetFinalPathNameByHandle, return a
-           NotImplementedError. */
-        PyErr_SetString(PyExc_NotImplementedError,
-            "GetFinalPathNameByHandle not available on this platform");
-        return -1;
+        /* If the OS doesn't have GetFinalPathNameByHandle, don't
+           traverse reparse point. */
+        traverse = FALSE;
     }
 
     hFile = CreateFileW(

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list