SUGGESTED FIX
--- io_util_md.c Fri Oct 13 11:53:52 2006
***************
*** 86,91 ****
--- 86,113 ----
}
}
+ WCHAR* prefixAbpath(const WCHAR* path, int pathlen, int abpathlen) {
+ WCHAR* pathbuf = NULL;
+ WCHAR* abpath = (WCHAR*)malloc(abpathlen * sizeof(WCHAR));
+ if (abpath) {
+ if (_wfullpath(abpath, path, abpathlen)) {
+ pathbuf = getPrefixed(abpath, abpathlen);
+ } else {
+ /* _wfullpath fails if the pathlength exceeds 32k wchar.
+ Instead of doing more fancy things we simply copy the
+ ps into the return buffer, the subsequent win32 API will
+ probably fail with FileNotFoundException, which is expected
+ */
+ pathbuf = (WCHAR*)malloc((pathlen + 6) * sizeof(WCHAR));
+ if (pathbuf != 0) {
+ wcscpy(pathbuf, path);
+ }
+ }
+ free(abpath);
+ }
+ return pathbuf;
+ }
+
/* If this returns NULL then an exception is pending */
WCHAR*
pathToNTPath(JNIEnv *env, jstring path, jboolean throwFNFE) {
***************
*** 102,108 ****
(ps[0] == L'\\' && ps[1] == L'\\' || //UNC
ps[1] == L':' && ps[2] == L'\\')) { //absolute
if (pathlen > max_path - 1) {
! pathbuf = getPrefixed(ps, pathlen);
} else {
pathbuf = (WCHAR*)malloc((pathlen + 6) * sizeof(WCHAR));
if (pathbuf != 0) {
--- 124,130 ----
(ps[0] == L'\\' && ps[1] == L'\\' || //UNC
ps[1] == L':' && ps[2] == L'\\')) { //absolute
if (pathlen > max_path - 1) {
! pathbuf = prefixAbpath(ps, pathlen, pathlen);
} else {
pathbuf = (WCHAR*)malloc((pathlen + 6) * sizeof(WCHAR));
if (pathbuf != 0) {
***************
*** 126,148 ****
int dirlen = currentDirLength(ps, pathlen);
if (dirlen + pathlen + 1 > max_path - 1) {
int abpathlen = dirlen + pathlen + 10;
! abpath = (WCHAR*)malloc(abpathlen * sizeof(WCHAR));
! if (abpath) {
! if (_wfullpath(abpath, ps, abpathlen)) {
! pathbuf = getPrefixed(abpath, abpathlen);
! } else {
! /* _wfullpath fails if the pathlength exceeds 32k wchar.
! Instead of doing more fancy things we simply copy the
! ps into the return buffer, the subsequent win32 API will
! probably fail with FileNotFoundException, which is expected
! */
! pathbuf = (WCHAR*)malloc((pathlen + 6) * sizeof(WCHAR));
! if (pathbuf != 0) {
! wcscpy(pathbuf, ps);
! }
! }
! free(abpath);
! }
} else {
pathbuf = (WCHAR*)malloc((pathlen + 6) * sizeof(WCHAR));
if (pathbuf != 0) {
--- 148,154 ----
int dirlen = currentDirLength(ps, pathlen);
if (dirlen + pathlen + 1 > max_path - 1) {
int abpathlen = dirlen + pathlen + 10;
! pathbuf = prefixAbpath(ps, pathlen, abpathlen);
} else {
pathbuf = (WCHAR*)malloc((pathlen + 6) * sizeof(WCHAR));
if (pathbuf != 0) {
|
EVALUATION
Regression introduced with the fix for #4403166. The implementation has a lopehole
when dealing with a un-canonicalized absolute filepath (means it's in absolute form
but has relative components, such as "../" or "./" in its path). As specified by
the Windows API, the "\\?\" prefix does not work with a relative path, obviously
this also includes the "relative path component". Invoking the _wfullpath to
"canonicalize" the path before adding the prefix to solve this problem. See suggested
fix.
The fix need go back to 5.0u and 6.0u asap.
|