From 0212da21b4edcceee7b3907f3da39c9c2b815621 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Tue, 2 Sep 2014 05:36:15 +0200 Subject: kernel32: Fix some of the issues in GetVolumePathNameW. --- dlls/kernel32/volume.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/dlls/kernel32/volume.c b/dlls/kernel32/volume.c index b723e9c..3c29901 100644 --- a/dlls/kernel32/volume.c +++ b/dlls/kernel32/volume.c @@ -1886,7 +1886,7 @@ BOOL WINAPI GetVolumePathNameW(LPCWSTR filename, LPWSTR volumepathname, DWORD bu if (filename[0] != '\\') { /* DOS-style paths revert to C:\ (anything not beginning with a slash) */ - last_pos = strlenW(fallbackpathW); + last_pos = strlenW(fallbackpathW) - 1; /* points to \\ */ filename = fallbackpathW; status = STATUS_SUCCESS; } @@ -1898,18 +1898,13 @@ BOOL WINAPI GetVolumePathNameW(LPCWSTR filename, LPWSTR volumepathname, DWORD bu } } - /* include the terminating backslash unless returning the full path */ - if (filename[last_pos] != '\0') - last_pos++; - /* require room to NULL terminate the string */ - if ((filename[last_pos] == '\\' && last_pos * sizeof(WCHAR) <= buflen) - || (last_pos+1) * sizeof(WCHAR) <= buflen) + if (last_pos + 1 <= buflen) { - memcpy(volumepathname, filename, last_pos*sizeof(WCHAR)); - /* remove the terminating backslash if the buffer is one byte short */ - if (filename[last_pos] == '\\' && (last_pos+1) * sizeof(WCHAR) > buflen) - last_pos--; + WCHAR *p; + memcpy(volumepathname, filename, last_pos * sizeof(WCHAR)); + if (last_pos + 2 <= buflen) volumepathname[last_pos++] = '\\'; volumepathname[last_pos] = '\0'; + for (p = volumepathname; *p; p++) if (*p == '/') *p = '\\'; } else status = STATUS_NAME_TOO_LONG; -- 2.1.0