# HG changeset patch # User mgronlun # Date 1534984285 -7200 # Thu Aug 23 02:31:25 2018 +0200 # Node ID e8e88e9f06768549926d5dfb380848178c16dec0 # Parent 7113784d24eb3c1ce86202ba94a9984edf71a87b [mq]: wcanonicalize_v1 diff --git a/src/java.base/windows/native/libjava/WinNTFileSystem_md.c b/src/java.base/windows/native/libjava/WinNTFileSystem_md.c --- a/src/java.base/windows/native/libjava/WinNTFileSystem_md.c +++ b/src/java.base/windows/native/libjava/WinNTFileSystem_md.c @@ -236,11 +236,7 @@ WCHAR canonicalPath[MAX_PATH_LENGTH]; WITH_UNICODE_STRING(env, pathname, path) { - /* we estimate the max length of memory needed as - "currentDir. length + pathname.length" - */ - int len = (int)wcslen(path); - len += currentDirLength(path, len); + const int len = (int)wcslen(path); if (len > MAX_PATH_LENGTH - 1) { WCHAR *cp = (WCHAR*)malloc(len * sizeof(WCHAR)); if (cp != NULL) { diff --git a/src/java.base/windows/native/libjava/canonicalize_md.c b/src/java.base/windows/native/libjava/canonicalize_md.c --- a/src/java.base/windows/native/libjava/canonicalize_md.c +++ b/src/java.base/windows/native/libjava/canonicalize_md.c @@ -404,11 +404,48 @@ return 0; } +/* Wide character version of canonicalize. Size is a wide-character size. */ + +int +wcanonicalize(WCHAR *orig_path, WCHAR *result, int size) +{ + WCHAR* p; + + /* Reject paths that contain wildcards */ + if (wwild(orig_path)) { + errno = EINVAL; + return -1; + } + + if (!_wfullpath(result, orig_path, size)) { + return -1; + } + + assert((int)wcslen(result) <= size); + assert(!wdots(result)); + + if (((result[0] <= L'z' && result[0] >= L'a') || (result[0] <= L'Z' && result[0] >= L'A')) + && (result[1] == L':') && (result[2] == L'\\')) { + /* Canonicalize drive letter */ + *result = (WCHAR)towupper(*result); + } else if (result[0] == L'\\' && result[1] == L'\\' + && (p = wcschr(&result[2], L'\\')) && wcschr(p + 1, L'\\')) { + /* valid UNC path */ + } else { + errno = EINVAL; + return -1; + } + + if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW(result)) { + return lastErrorReportable() ? -1 : 0; + } + return 0; +} /* Wide character version of canonicalize. Size is a wide-character size. */ int -wcanonicalize(WCHAR *orig_path, WCHAR *result, int size) +wcanonicalize_old(WCHAR *orig_path, WCHAR *result, int size) { WIN32_FIND_DATAW fd; HANDLE h;