mirror of
https://gitlab.winehq.org/wine/wine-staging.git
synced 2024-11-21 16:46:54 -08:00
kernel32-GetVolumePathName: Fix possible leak and merge patches 1 and 5.
This commit is contained in:
parent
819a738d3d
commit
5cab0e1b8f
@ -345,7 +345,6 @@ kernel32-GetVolumePathName.ok:
|
||||
$(call APPLY_FILE,kernel32-GetVolumePathName/0002-kernel32-Convert-GetVolumePathName-tests-into-a-list.patch)
|
||||
$(call APPLY_FILE,kernel32-GetVolumePathName/0003-kernel32-Add-a-bunch-more-GetVolumePathName-tests.patch)
|
||||
$(call APPLY_FILE,kernel32-GetVolumePathName/0004-kernel32-tests-Add-a-lot-of-picky-GetVolumePathName-.patch)
|
||||
$(call APPLY_FILE,kernel32-GetVolumePathName/0005-kernel32-Fix-some-of-the-issues-in-GetVolumePathName.patch)
|
||||
@( \
|
||||
echo '+ { "kernel32-GetVolumePathName", "Erich E. Hoover", "Implement GetVolumePathName." },'; \
|
||||
) > kernel32-GetVolumePathName.ok
|
||||
|
@ -1,12 +1,12 @@
|
||||
From 98c28e54799dc51257ec44389eac5384b2ddb609 Mon Sep 17 00:00:00 2001
|
||||
From 719e096c6ca40ef86cd8f23d419807cdcd002656 Mon Sep 17 00:00:00 2001
|
||||
From: "Erich E. Hoover" <erich.e.hoover@gmail.com>
|
||||
Date: Sat, 25 Jan 2014 09:47:12 -0700
|
||||
Subject: kernel32: Implement GetVolumePathName.
|
||||
|
||||
---
|
||||
dlls/kernel32/tests/volume.c | 3 -
|
||||
dlls/kernel32/volume.c | 129 ++++++++++++++++++++++++++++++++++++++-----
|
||||
2 files changed, 115 insertions(+), 17 deletions(-)
|
||||
dlls/kernel32/tests/volume.c | 3 --
|
||||
dlls/kernel32/volume.c | 123 ++++++++++++++++++++++++++++++++++++++-----
|
||||
2 files changed, 109 insertions(+), 17 deletions(-)
|
||||
|
||||
diff --git a/dlls/kernel32/tests/volume.c b/dlls/kernel32/tests/volume.c
|
||||
index 61da509..4b3bdf5 100644
|
||||
@ -29,7 +29,7 @@ index 61da509..4b3bdf5 100644
|
||||
|
||||
/* test an invalid path */
|
||||
diff --git a/dlls/kernel32/volume.c b/dlls/kernel32/volume.c
|
||||
index d396764..b723e9c 100644
|
||||
index d396764..8826dd2 100644
|
||||
--- a/dlls/kernel32/volume.c
|
||||
+++ b/dlls/kernel32/volume.c
|
||||
@@ -1786,7 +1786,7 @@ BOOL WINAPI GetVolumePathNameA(LPCSTR filename, LPSTR volumepathname, DWORD bufl
|
||||
@ -71,7 +71,7 @@ index d396764..b723e9c 100644
|
||||
|
||||
if (!filename || !volumepathname || !buflen)
|
||||
{
|
||||
@@ -1815,24 +1830,110 @@ BOOL WINAPI GetVolumePathNameW(LPCWSTR filename, LPWSTR volumepathname, DWORD bu
|
||||
@@ -1815,24 +1830,104 @@ BOOL WINAPI GetVolumePathNameW(LPCWSTR filename, LPWSTR volumepathname, DWORD bu
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -111,7 +111,6 @@ index d396764..b723e9c 100644
|
||||
+ status = STATUS_OBJECT_NAME_INVALID;
|
||||
+ goto cleanup;
|
||||
+ }
|
||||
+ RtlFreeAnsiString( &unix_name );
|
||||
+ if (first_run)
|
||||
+ {
|
||||
+ first_run = FALSE;
|
||||
@ -120,9 +119,11 @@ index d396764..b723e9c 100644
|
||||
+ else if (st.st_dev != search_dev)
|
||||
+ {
|
||||
+ /* folder is on a new filesystem, return the last folder */
|
||||
+ RtlFreeAnsiString( &unix_name );
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+ RtlFreeAnsiString( &unix_name );
|
||||
+ last_pos = pos;
|
||||
+ c = strrchrW( volumenameW, '\\' );
|
||||
+ if (c != NULL)
|
||||
@ -135,7 +136,7 @@ index d396764..b723e9c 100644
|
||||
+ 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;
|
||||
+ }
|
||||
@ -154,32 +155,25 @@ index d396764..b723e9c 100644
|
||||
|
||||
- SetLastError(ERROR_INVALID_NAME);
|
||||
- return FALSE;
|
||||
+ /* 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';
|
||||
+ }
|
||||
+ else
|
||||
+ status = STATUS_NAME_TOO_LONG;
|
||||
+
|
||||
+ if (status == STATUS_SUCCESS)
|
||||
+ {
|
||||
+ /* Normalize path */
|
||||
+ for (p = volumepathname; *p; p++) if (*p == '/') *p = '\\';
|
||||
+
|
||||
+ /* DOS-style paths always return upper-case drive letters */
|
||||
+ if (volumepathname[1] == ':')
|
||||
+ {
|
||||
+ /* DOS-style paths always return upper-case drive letters */
|
||||
+ volumepathname[0] = toupper(volumepathname[0]);
|
||||
+ }
|
||||
+
|
||||
+ TRACE("Successfully translated path %s to mount-point %s\n",
|
||||
+ debugstr_w(filename), debugstr_w(volumepathname));
|
||||
+ }
|
||||
+ else
|
||||
+ status = STATUS_NAME_TOO_LONG;
|
||||
+
|
||||
+cleanup:
|
||||
+ HeapFree( GetProcessHeap(), 0, volumenameW );
|
||||
|
@ -1,10 +1,10 @@
|
||||
From 7739a32bd18ed7912e610941f6cfb273748b82cd Mon Sep 17 00:00:00 2001
|
||||
From f01a3110045b59483ec4172ad782198f44ed7639 Mon Sep 17 00:00:00 2001
|
||||
From: "Erich E. Hoover" <erich.e.hoover@gmail.com>
|
||||
Date: Sat, 25 Jan 2014 09:53:39 -0700
|
||||
Subject: kernel32: Convert GetVolumePathName tests into a list.
|
||||
|
||||
---
|
||||
dlls/kernel32/tests/volume.c | 137 +++++++++++++++++++++++-------------------
|
||||
dlls/kernel32/tests/volume.c | 137 +++++++++++++++++++++++--------------------
|
||||
1 file changed, 74 insertions(+), 63 deletions(-)
|
||||
|
||||
diff --git a/dlls/kernel32/tests/volume.c b/dlls/kernel32/tests/volume.c
|
||||
@ -166,5 +166,5 @@ index 4b3bdf5..f15269c 100644
|
||||
|
||||
static void test_GetVolumePathNamesForVolumeNameA(void)
|
||||
--
|
||||
1.7.9.5
|
||||
2.1.0
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
From a6eb5189737a6aeb31dd305649f407ca5ddc9faf Mon Sep 17 00:00:00 2001
|
||||
From 93f0d790f4b5f7945847c8b5190c9da11d6160fa Mon Sep 17 00:00:00 2001
|
||||
From: "Erich E. Hoover" <erich.e.hoover@gmail.com>
|
||||
Date: Sat, 25 Jan 2014 09:54:39 -0700
|
||||
Subject: kernel32: Add a bunch more GetVolumePathName tests.
|
||||
|
||||
---
|
||||
dlls/kernel32/tests/volume.c | 28 ++++++++++++++++++++++++++++
|
||||
dlls/kernel32/tests/volume.c | 28 ++++++++++++++++++++++++++++
|
||||
1 file changed, 28 insertions(+)
|
||||
|
||||
diff --git a/dlls/kernel32/tests/volume.c b/dlls/kernel32/tests/volume.c
|
||||
@ -47,5 +47,5 @@ index f15269c..e17cc16 100644
|
||||
BOOL ret, success;
|
||||
DWORD error;
|
||||
--
|
||||
1.7.9.5
|
||||
2.1.0
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
From 8ea2e534c88b3dc0f76b4ae41695802871793ab9 Mon Sep 17 00:00:00 2001
|
||||
From 58660ba82873512fe46e897274f569865f8af80f Mon Sep 17 00:00:00 2001
|
||||
From: Sebastian Lackner <sebastian@fds-team.de>
|
||||
Date: Tue, 2 Sep 2014 05:23:37 +0200
|
||||
Subject: kernel32/tests: Add a lot of picky GetVolumePathName tests.
|
||||
|
@ -1,49 +0,0 @@
|
||||
From 0212da21b4edcceee7b3907f3da39c9c2b815621 Mon Sep 17 00:00:00 2001
|
||||
From: Sebastian Lackner <sebastian@fds-team.de>
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user