Commit 3465646d authored by Bruno Jesus's avatar Bruno Jesus Committed by Alexandre Julliard

kernel32: Fix parameters checking for GetVolumePathName().

parent 1c13e622
...@@ -606,7 +606,6 @@ static void test_GetVolumePathNameA(void) ...@@ -606,7 +606,6 @@ static void test_GetVolumePathNameA(void)
ret = pGetVolumePathNameA(NULL, NULL, 0); ret = pGetVolumePathNameA(NULL, NULL, 0);
error = GetLastError(); error = GetLastError();
ok(!ret, "expected failure\n"); ok(!ret, "expected failure\n");
todo_wine
ok(error == ERROR_INVALID_PARAMETER ok(error == ERROR_INVALID_PARAMETER
|| broken( error == 0xdeadbeef) /* <=XP */, || broken( error == 0xdeadbeef) /* <=XP */,
"expected ERROR_INVALID_PARAMETER got %u\n", error); "expected ERROR_INVALID_PARAMETER got %u\n", error);
...@@ -615,7 +614,6 @@ todo_wine ...@@ -615,7 +614,6 @@ todo_wine
ret = pGetVolumePathNameA("", NULL, 0); ret = pGetVolumePathNameA("", NULL, 0);
error = GetLastError(); error = GetLastError();
ok(!ret, "expected failure\n"); ok(!ret, "expected failure\n");
todo_wine
ok(error == ERROR_INVALID_PARAMETER ok(error == ERROR_INVALID_PARAMETER
|| broken( error == 0xdeadbeef) /* <=XP */, || broken( error == 0xdeadbeef) /* <=XP */,
"expected ERROR_INVALID_PARAMETER got %u\n", error); "expected ERROR_INVALID_PARAMETER got %u\n", error);
...@@ -624,7 +622,6 @@ todo_wine ...@@ -624,7 +622,6 @@ todo_wine
ret = pGetVolumePathNameA(pathC1, NULL, 0); ret = pGetVolumePathNameA(pathC1, NULL, 0);
error = GetLastError(); error = GetLastError();
ok(!ret, "expected failure\n"); ok(!ret, "expected failure\n");
todo_wine
ok(error == ERROR_INVALID_PARAMETER ok(error == ERROR_INVALID_PARAMETER
|| broken(error == ERROR_FILENAME_EXCED_RANGE) /* <=XP */, || broken(error == ERROR_FILENAME_EXCED_RANGE) /* <=XP */,
"expected ERROR_INVALID_PARAMETER got %u\n", error); "expected ERROR_INVALID_PARAMETER got %u\n", error);
...@@ -633,7 +630,6 @@ todo_wine ...@@ -633,7 +630,6 @@ todo_wine
ret = pGetVolumePathNameA(pathC1, volume, 0); ret = pGetVolumePathNameA(pathC1, volume, 0);
error = GetLastError(); error = GetLastError();
ok(!ret, "expected failure\n"); ok(!ret, "expected failure\n");
todo_wine
ok(error == ERROR_INVALID_PARAMETER ok(error == ERROR_INVALID_PARAMETER
|| broken(error == ERROR_FILENAME_EXCED_RANGE ) /* <=XP */, || broken(error == ERROR_FILENAME_EXCED_RANGE ) /* <=XP */,
"expected ERROR_INVALID_PARAMETER got %u\n", error); "expected ERROR_INVALID_PARAMETER got %u\n", error);
...@@ -642,7 +638,6 @@ todo_wine ...@@ -642,7 +638,6 @@ todo_wine
ret = pGetVolumePathNameA(pathC1, volume, 1); ret = pGetVolumePathNameA(pathC1, volume, 1);
error = GetLastError(); error = GetLastError();
ok(!ret, "expected failure\n"); ok(!ret, "expected failure\n");
todo_wine
ok(error == ERROR_FILENAME_EXCED_RANGE, "expected ERROR_FILENAME_EXCED_RANGE got %u\n", error); ok(error == ERROR_FILENAME_EXCED_RANGE, "expected ERROR_FILENAME_EXCED_RANGE got %u\n", error);
volume[0] = '\0'; volume[0] = '\0';
...@@ -664,6 +659,14 @@ todo_wine ...@@ -664,6 +659,14 @@ todo_wine
ok(ret, "expected success\n"); ok(ret, "expected success\n");
todo_wine todo_wine
ok(!strcmp(expected, volume), "expected name '%s', returned '%s'\n", expected, volume); 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) static void test_GetVolumePathNamesForVolumeNameA(void)
......
...@@ -1782,12 +1782,14 @@ BOOL WINAPI GetDiskFreeSpaceA( LPCSTR root, LPDWORD cluster_sectors, ...@@ -1782,12 +1782,14 @@ BOOL WINAPI GetDiskFreeSpaceA( LPCSTR root, LPDWORD cluster_sectors,
BOOL WINAPI GetVolumePathNameA(LPCSTR filename, LPSTR volumepathname, DWORD buflen) BOOL WINAPI GetVolumePathNameA(LPCSTR filename, LPSTR volumepathname, DWORD buflen)
{ {
BOOL ret; BOOL ret;
WCHAR *filenameW = NULL, *volumeW; WCHAR *filenameW = NULL, *volumeW = NULL;
FIXME("(%s, %p, %d), stub!\n", debugstr_a(filename), volumepathname, buflen); FIXME("(%s, %p, %d), stub!\n", debugstr_a(filename), volumepathname, buflen);
if (filename && !(filenameW = FILE_name_AtoW( filename, FALSE ))) return FALSE; if (filename && !(filenameW = FILE_name_AtoW( filename, FALSE )))
if (!(volumeW = HeapAlloc( GetProcessHeap(), 0, buflen * sizeof(WCHAR) ))) return FALSE; return FALSE;
if (volumepathname && !(volumeW = HeapAlloc( GetProcessHeap(), 0, buflen * sizeof(WCHAR) )))
return FALSE;
if ((ret = GetVolumePathNameW( filenameW, volumeW, buflen ))) if ((ret = GetVolumePathNameW( filenameW, volumeW, buflen )))
FILE_name_WtoA( volumeW, -1, volumepathname, buflen ); FILE_name_WtoA( volumeW, -1, volumepathname, buflen );
...@@ -1805,14 +1807,27 @@ BOOL WINAPI GetVolumePathNameW(LPCWSTR filename, LPWSTR volumepathname, DWORD bu ...@@ -1805,14 +1807,27 @@ BOOL WINAPI GetVolumePathNameW(LPCWSTR filename, LPWSTR volumepathname, DWORD bu
FIXME("(%s, %p, %d), stub!\n", debugstr_w(filename), volumepathname, buflen); 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[0] = p[0];
volumepathname[1] = ':'; volumepathname[1] = ':';
volumepathname[2] = '\\'; volumepathname[2] = '\\';
volumepathname[3] = 0; volumepathname[3] = 0;
return TRUE; return TRUE;
} }
SetLastError(ERROR_INVALID_NAME);
return FALSE; return FALSE;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment