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

Skip to content

Commit c8be840

Browse files
committed
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.
1 parent a87d586 commit c8be840

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

Modules/posixmodule.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,11 @@ get_target_path(HANDLE hdl, wchar_t **target_path)
11021102
return FALSE;
11031103

11041104
buf = (wchar_t *)malloc((buf_size+1)*sizeof(wchar_t));
1105+
if (!buf) {
1106+
SetLastError(ERROR_OUTOFMEMORY);
1107+
return FALSE;
1108+
}
1109+
11051110
result_length = Py_GetFinalPathNameByHandleW(hdl,
11061111
buf, buf_size, VOLUME_NAME_DOS);
11071112

@@ -1136,11 +1141,9 @@ win32_xstat_impl(const char *path, struct win32_stat *result,
11361141
const char *dot;
11371142

11381143
if(!check_GetFinalPathNameByHandle()) {
1139-
/* If the OS doesn't have GetFinalPathNameByHandle, return a
1140-
NotImplementedError. */
1141-
PyErr_SetString(PyExc_NotImplementedError,
1142-
"GetFinalPathNameByHandle not available on this platform");
1143-
return -1;
1144+
/* If the OS doesn't have GetFinalPathNameByHandle, don't
1145+
traverse reparse point. */
1146+
traverse = FALSE;
11441147
}
11451148

11461149
hFile = CreateFileA(
@@ -1234,11 +1237,9 @@ win32_xstat_impl_w(const wchar_t *path, struct win32_stat *result,
12341237
const wchar_t *dot;
12351238

12361239
if(!check_GetFinalPathNameByHandle()) {
1237-
/* If the OS doesn't have GetFinalPathNameByHandle, return a
1238-
NotImplementedError. */
1239-
PyErr_SetString(PyExc_NotImplementedError,
1240-
"GetFinalPathNameByHandle not available on this platform");
1241-
return -1;
1240+
/* If the OS doesn't have GetFinalPathNameByHandle, don't
1241+
traverse reparse point. */
1242+
traverse = FALSE;
12421243
}
12431244

12441245
hFile = CreateFileW(

0 commit comments

Comments
 (0)