kernel32: Fix parameters checking for GetVolumePathName()

Bruno Jesus 00cpxxx at gmail.com
Tue Jul 30 18:45:30 CDT 2013


In order to simplify patch 97599 I need to fix the parameters checking first.

http://source.winehq.org/patches/data/97599
-------------- next part --------------
diff --git a/dlls/kernel32/tests/volume.c b/dlls/kernel32/tests/volume.c
index e63a2ef..0a58f40 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';
diff --git a/dlls/kernel32/volume.c b/dlls/kernel32/volume.c
index 2e0cc8a..5537c06 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,6 +1807,12 @@ BOOL WINAPI GetVolumePathNameW(LPCWSTR filename, LPWSTR volumepathname, DWORD bu
 
     FIXME("(%s, %p, %d), stub!\n", debugstr_w(filename), volumepathname, buflen);
 
+    if(!filename || !volumepathname || !buflen)
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+
     if (p && tolowerW(p[0]) >= 'a' && tolowerW(p[0]) <= 'z' && p[1] ==':' && p[2] == '\\' && buflen >= 4)
     {
         volumepathname[0] = p[0];
@@ -1813,6 +1821,8 @@ BOOL WINAPI GetVolumePathNameW(LPCWSTR filename, LPWSTR volumepathname, DWORD bu
         volumepathname[3] = 0;
         return TRUE;
     }
+
+    SetLastError(ERROR_FILENAME_EXCED_RANGE);
     return FALSE;
 }
 


More information about the wine-patches mailing list