Allow very long path names for .inf files by using a dynamic buffer
authorHervé Poussineau <hpoussin@reactos.org>
Wed, 26 Oct 2005 20:42:19 +0000 (20:42 +0000)
committerHervé Poussineau <hpoussin@reactos.org>
Wed, 26 Oct 2005 20:42:19 +0000 (20:42 +0000)
Check return code of GetFullPathNameW

svn path=/trunk/; revision=18780

reactos/lib/setupapi/devinst.c

index 8a7d130..97dcb84 100644 (file)
@@ -4204,6 +4204,7 @@ SetupDiBuildDriverInfoList(
     WCHAR ManufacturerSection[LINE_LEN + 1];
     LPWSTR HardwareIDs = NULL;
     LPWSTR CompatibleIDs = NULL;
     WCHAR ManufacturerSection[LINE_LEN + 1];
     LPWSTR HardwareIDs = NULL;
     LPWSTR CompatibleIDs = NULL;
+    LPWSTR FullInfFileName = NULL;
     FILETIME DriverDate;
     DWORDLONG DriverVersion = 0;
     DWORD RequiredSize;
     FILETIME DriverDate;
     DWORDLONG DriverVersion = 0;
     DWORD RequiredSize;
@@ -4325,18 +4326,31 @@ SetupDiBuildDriverInfoList(
         if (Result)
         {
             LPCWSTR filename;
         if (Result)
         {
             LPCWSTR filename;
-            WCHAR FullInfFileName[MAX_PATH];
             LPWSTR pFullFilename;
 
             if (*InstallParams.DriverPath)
             {
             LPWSTR pFullFilename;
 
             if (*InstallParams.DriverPath)
             {
-                GetFullPathNameW(InstallParams.DriverPath, MAX_PATH, FullInfFileName, &pFullFilename);
+                DWORD len;
+                len = GetFullPathNameW(InstallParams.DriverPath, 0, NULL, NULL);
+                if (len == 0)
+                    goto done;
+                FullInfFileName = HeapAlloc(GetProcessHeap(), 0, len + MAX_PATH);
+                if (!FullInfFileName)
+                    goto done;
+                len = GetFullPathNameW(InstallParams.DriverPath, len, FullInfFileName, NULL);
+                if (len == 0)
+                    goto done;
                 if (*FullInfFileName && FullInfFileName[wcslen(FullInfFileName) - 1] != '\\')
                     wcscat(FullInfFileName, L"\\");
                 pFullFilename = &FullInfFileName[wcslen(FullInfFileName)];
             }
             else
                 if (*FullInfFileName && FullInfFileName[wcslen(FullInfFileName) - 1] != '\\')
                     wcscat(FullInfFileName, L"\\");
                 pFullFilename = &FullInfFileName[wcslen(FullInfFileName)];
             }
             else
+            {
+                FullInfFileName = HeapAlloc(GetProcessHeap(), 0, MAX_PATH);
+                if (!FullInfFileName)
+                    goto done;
                 pFullFilename = &FullInfFileName[0];
                 pFullFilename = &FullInfFileName[0];
+            }
 
             for (filename = (LPCWSTR)Buffer; *filename; filename += wcslen(filename) + 1)
             {
 
             for (filename = (LPCWSTR)Buffer; *filename; filename += wcslen(filename) + 1)
             {
@@ -4565,6 +4579,7 @@ done:
     HeapFree(GetProcessHeap(), 0, ManufacturerName);
     HeapFree(GetProcessHeap(), 0, HardwareIDs);
     HeapFree(GetProcessHeap(), 0, CompatibleIDs);
     HeapFree(GetProcessHeap(), 0, ManufacturerName);
     HeapFree(GetProcessHeap(), 0, HardwareIDs);
     HeapFree(GetProcessHeap(), 0, CompatibleIDs);
+    HeapFree(GetProcessHeap(), 0, FullInfFileName);
     if (currentInfFileDetails)
         DereferenceInfFile(currentInfFileDetails);
     HeapFree(GetProcessHeap(), 0, Buffer);
     if (currentInfFileDetails)
         DereferenceInfFile(currentInfFileDetails);
     HeapFree(GetProcessHeap(), 0, Buffer);