Commit ea87ae3a authored by Brian Curtin's avatar Brian Curtin

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.
parent 9c99824d
...@@ -1102,6 +1102,11 @@ get_target_path(HANDLE hdl, wchar_t **target_path) ...@@ -1102,6 +1102,11 @@ get_target_path(HANDLE hdl, wchar_t **target_path)
return FALSE; return FALSE;
buf = (wchar_t *)malloc((buf_size+1)*sizeof(wchar_t)); buf = (wchar_t *)malloc((buf_size+1)*sizeof(wchar_t));
if (!buf) {
SetLastError(ERROR_OUTOFMEMORY);
return FALSE;
}
result_length = Py_GetFinalPathNameByHandleW(hdl, result_length = Py_GetFinalPathNameByHandleW(hdl,
buf, buf_size, VOLUME_NAME_DOS); buf, buf_size, VOLUME_NAME_DOS);
...@@ -1136,11 +1141,9 @@ win32_xstat_impl(const char *path, struct win32_stat *result, ...@@ -1136,11 +1141,9 @@ win32_xstat_impl(const char *path, struct win32_stat *result,
const char *dot; const char *dot;
if(!check_GetFinalPathNameByHandle()) { if(!check_GetFinalPathNameByHandle()) {
/* If the OS doesn't have GetFinalPathNameByHandle, return a /* If the OS doesn't have GetFinalPathNameByHandle, don't
NotImplementedError. */ traverse reparse point. */
PyErr_SetString(PyExc_NotImplementedError, traverse = FALSE;
"GetFinalPathNameByHandle not available on this platform");
return -1;
} }
hFile = CreateFileA( hFile = CreateFileA(
...@@ -1234,11 +1237,9 @@ win32_xstat_impl_w(const wchar_t *path, struct win32_stat *result, ...@@ -1234,11 +1237,9 @@ win32_xstat_impl_w(const wchar_t *path, struct win32_stat *result,
const wchar_t *dot; const wchar_t *dot;
if(!check_GetFinalPathNameByHandle()) { if(!check_GetFinalPathNameByHandle()) {
/* If the OS doesn't have GetFinalPathNameByHandle, return a /* If the OS doesn't have GetFinalPathNameByHandle, don't
NotImplementedError. */ traverse reparse point. */
PyErr_SetString(PyExc_NotImplementedError, traverse = FALSE;
"GetFinalPathNameByHandle not available on this platform");
return -1;
} }
hFile = CreateFileW( hFile = CreateFileW(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment