Bruno Jesus : kernel32: Fix parameters checking for GetVolumePathName().
Alexandre Julliard
julliard at winehq.org
Mon Sep 9 16:08:08 CDT 2013
Module: wine
Branch: master
Commit: 3465646d446f2537faeb9b8f0a5d04cc3f1048e8
URL: http://source.winehq.org/git/wine.git/?a=commit;h=3465646d446f2537faeb9b8f0a5d04cc3f1048e8
Author: Bruno Jesus <00cpxxx at gmail.com>
Date: Fri Sep 6 12:19:34 2013 -0300
kernel32: Fix parameters checking for GetVolumePathName().
---
dlls/kernel32/tests/volume.c | 13 ++++++++-----
dlls/kernel32/volume.c | 23 +++++++++++++++++++----
2 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/dlls/kernel32/tests/volume.c b/dlls/kernel32/tests/volume.c
index e63a2ef..02446ea 100644
--- a/dlls/kernel32/tests/volume.c
+++ b/dlls/kernel32/tests/volume.c
@@ -606,7 +606,6 @@ static void test_GetVolumePathNameA(void)
ret = pGetVolumePathNameA(NULL, NULL, 0);
error = GetLastError();
ok(!ret, "expected failure\n");
-todo_wine
ok(error == ERROR_INVALID_PARAMETER
|| broken( error == 0xdeadbeef) /* <=XP */,
"expected ERROR_INVALID_PARAMETER got %u\n", error);
@@ -615,7 +614,6 @@ todo_wine
ret = pGetVolumePathNameA("", NULL, 0);
error = GetLastError();
ok(!ret, "expected failure\n");
-todo_wine
ok(error == ERROR_INVALID_PARAMETER
|| broken( error == 0xdeadbeef) /* <=XP */,
"expected ERROR_INVALID_PARAMETER got %u\n", error);
@@ -624,7 +622,6 @@ todo_wine
ret = pGetVolumePathNameA(pathC1, NULL, 0);
error = GetLastError();
ok(!ret, "expected failure\n");
-todo_wine
ok(error == ERROR_INVALID_PARAMETER
|| broken(error == ERROR_FILENAME_EXCED_RANGE) /* <=XP */,
"expected ERROR_INVALID_PARAMETER got %u\n", error);
@@ -633,7 +630,6 @@ todo_wine
ret = pGetVolumePathNameA(pathC1, volume, 0);
error = GetLastError();
ok(!ret, "expected failure\n");
-todo_wine
ok(error == ERROR_INVALID_PARAMETER
|| broken(error == ERROR_FILENAME_EXCED_RANGE ) /* <=XP */,
"expected ERROR_INVALID_PARAMETER got %u\n", error);
@@ -642,7 +638,6 @@ todo_wine
ret = pGetVolumePathNameA(pathC1, volume, 1);
error = GetLastError();
ok(!ret, "expected failure\n");
-todo_wine
ok(error == ERROR_FILENAME_EXCED_RANGE, "expected ERROR_FILENAME_EXCED_RANGE got %u\n", error);
volume[0] = '\0';
@@ -664,6 +659,14 @@ todo_wine
ok(ret, "expected success\n");
todo_wine
ok(!strcmp(expected, volume), "expected name '%s', returned '%s'\n", expected, volume);
+
+ /* test an invalid path */
+ SetLastError( 0xdeadbeef );
+ ret = pGetVolumePathNameA("\\\\$$$", volume, 1);
+ error = GetLastError();
+ ok(!ret, "expected failure\n");
+ ok(error == ERROR_INVALID_NAME || broken(ERROR_FILENAME_EXCED_RANGE) /* <=2000 */,
+ "expected ERROR_INVALID_NAME got %u\n", error);
}
static void test_GetVolumePathNamesForVolumeNameA(void)
diff --git a/dlls/kernel32/volume.c b/dlls/kernel32/volume.c
index 72b04df..1509d73 100644
--- a/dlls/kernel32/volume.c
+++ b/dlls/kernel32/volume.c
@@ -1782,12 +1782,14 @@ BOOL WINAPI GetDiskFreeSpaceA( LPCSTR root, LPDWORD cluster_sectors,
BOOL WINAPI GetVolumePathNameA(LPCSTR filename, LPSTR volumepathname, DWORD buflen)
{
BOOL ret;
- WCHAR *filenameW = NULL, *volumeW;
+ WCHAR *filenameW = NULL, *volumeW = NULL;
FIXME("(%s, %p, %d), stub!\n", debugstr_a(filename), volumepathname, buflen);
- if (filename && !(filenameW = FILE_name_AtoW( filename, FALSE ))) return FALSE;
- if (!(volumeW = HeapAlloc( GetProcessHeap(), 0, buflen * sizeof(WCHAR) ))) return FALSE;
+ if (filename && !(filenameW = FILE_name_AtoW( filename, FALSE )))
+ return FALSE;
+ if (volumepathname && !(volumeW = HeapAlloc( GetProcessHeap(), 0, buflen * sizeof(WCHAR) )))
+ return FALSE;
if ((ret = GetVolumePathNameW( filenameW, volumeW, buflen )))
FILE_name_WtoA( volumeW, -1, volumepathname, buflen );
@@ -1805,14 +1807,27 @@ BOOL WINAPI GetVolumePathNameW(LPCWSTR filename, LPWSTR volumepathname, DWORD bu
FIXME("(%s, %p, %d), stub!\n", debugstr_w(filename), volumepathname, buflen);
- if (p && tolowerW(p[0]) >= 'a' && tolowerW(p[0]) <= 'z' && p[1] ==':' && p[2] == '\\' && buflen >= 4)
+ if (!filename || !volumepathname || !buflen)
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+
+ if (p && tolowerW(p[0]) >= 'a' && tolowerW(p[0]) <= 'z' && p[1] ==':' && p[2] == '\\')
{
+ if (buflen < 4)
+ {
+ SetLastError(ERROR_FILENAME_EXCED_RANGE);
+ return FALSE;
+ }
volumepathname[0] = p[0];
volumepathname[1] = ':';
volumepathname[2] = '\\';
volumepathname[3] = 0;
return TRUE;
}
+
+ SetLastError(ERROR_INVALID_NAME);
return FALSE;
}
More information about the wine-cvs
mailing list