src/windows/native/java/io/WinNTFileSystem_md.c

Print this page

        

*** 86,110 **** * if the function fails. */ static WCHAR* getFinalPath(const WCHAR *path) { HANDLE h; ! WCHAR *result; DWORD error; /* Need Windows Vista or newer to get the final path */ if (GetFinalPathNameByHandle_func == NULL) return NULL; ! h = CreateFileW(path, ! FILE_READ_ATTRIBUTES, ! FILE_SHARE_DELETE | ! FILE_SHARE_READ | FILE_SHARE_WRITE, ! NULL, ! OPEN_EXISTING, ! FILE_FLAG_BACKUP_SEMANTICS, ! NULL); if (h == INVALID_HANDLE_VALUE) return NULL; /** * Allocate a buffer for the resolved path. For a long path we may need --- 86,105 ---- * if the function fails. */ static WCHAR* getFinalPath(const WCHAR *path) { HANDLE h; ! WCHAR *result=NULL, *resultTemp=NULL; DWORD error; /* Need Windows Vista or newer to get the final path */ if (GetFinalPathNameByHandle_func == NULL) return NULL; ! h = CreateFileW(path, FILE_READ_ATTRIBUTES, ! FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, ! NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if (h == INVALID_HANDLE_VALUE) return NULL; /** * Allocate a buffer for the resolved path. For a long path we may need
*** 113,128 **** result = (WCHAR*)malloc(MAX_PATH * sizeof(WCHAR)); if (result != NULL) { DWORD len = (*GetFinalPathNameByHandle_func)(h, result, MAX_PATH, 0); if (len >= MAX_PATH) { /* retry with a buffer of the right size */ ! result = (WCHAR*)realloc(result, (len+1) * sizeof(WCHAR)); ! if (result != NULL) { ! len = (*GetFinalPathNameByHandle_func)(h, result, len, 0); ! } else { ! len = 0; } } if (len > 0) { /** * Strip prefix (should be \\?\ or \\?\UNC) */ --- 108,124 ---- result = (WCHAR*)malloc(MAX_PATH * sizeof(WCHAR)); if (result != NULL) { DWORD len = (*GetFinalPathNameByHandle_func)(h, result, MAX_PATH, 0); if (len >= MAX_PATH) { /* retry with a buffer of the right size */ ! resultTemp = (WCHAR*)realloc(result, (len+1) * sizeof(WCHAR)); ! if(resultTemp == NULL) { ! free(result); ! return NULL; } + result = resultTemp; + len = (*GetFinalPathNameByHandle_func)(h, result, len, 0); } if (len > 0) { /** * Strip prefix (should be \\?\ or \\?\UNC) */
*** 256,266 **** WITH_UNICODE_STRING(env, canonicalPrefixString, canonicalPrefix) { WITH_UNICODE_STRING(env, pathWithCanonicalPrefixString, pathWithCanonicalPrefix) { int len = (int)wcslen(canonicalPrefix) + MAX_PATH; if (len > MAX_PATH_LENGTH) { WCHAR *cp = (WCHAR*)malloc(len * sizeof(WCHAR)); ! if (cp != NULL) { if (wcanonicalizeWithPrefix(canonicalPrefix, pathWithCanonicalPrefix, cp, len) >= 0) { rv = (*env)->NewString(env, cp, (jsize)wcslen(cp)); } --- 252,263 ---- WITH_UNICODE_STRING(env, canonicalPrefixString, canonicalPrefix) { WITH_UNICODE_STRING(env, pathWithCanonicalPrefixString, pathWithCanonicalPrefix) { int len = (int)wcslen(canonicalPrefix) + MAX_PATH; if (len > MAX_PATH_LENGTH) { WCHAR *cp = (WCHAR*)malloc(len * sizeof(WCHAR)); ! if (cp != NULL) ! { if (wcanonicalizeWithPrefix(canonicalPrefix, pathWithCanonicalPrefix, cp, len) >= 0) { rv = (*env)->NewString(env, cp, (jsize)wcslen(cp)); }