kernel32: Fix parameters checking for GetVolumePathName().

This commit is contained in:
Bruno Jesus 2013-09-06 12:19:34 -03:00 committed by Alexandre Julliard
parent 1c13e6221a
commit 3465646d44
2 changed files with 27 additions and 9 deletions

View File

@ -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)

View File

@ -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;
}