[HAL] Fix parser bugs in HalpDebugPciDumpBus (#1895)
authorStanislav Motylkov <x86corez@gmail.com>
Mon, 23 Sep 2019 21:46:23 +0000 (00:46 +0300)
committerHermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
Mon, 23 Sep 2019 21:46:23 +0000 (23:46 +0200)
- Match subclass properly, don't match third subclass.
- Don't match subclass from next class, add ClassEnd boundary.
- Use class name if subclass name not available.
- Gracefully return "Unknown" if no class name found.

hal/halx86/legacy/bussupp.c

index b8a7cb8..aad2583 100644 (file)
@@ -809,7 +809,7 @@ HalpDebugPciDumpBus(IN ULONG i,
                     IN ULONG k,
                     IN PPCI_COMMON_CONFIG PciData)
 {
-    PCHAR p, ClassName, SubClassName, VendorName, ProductName, SubVendorName;
+    PCHAR p, ClassName, ClassEnd, SubClassName, VendorName, ProductName, SubVendorName;
     ULONG Length;
     CHAR LookupString[16] = "";
     CHAR bSubClassName[64] = "";
@@ -824,19 +824,28 @@ HalpDebugPciDumpBus(IN ULONG i,
     if (ClassName)
     {
         /* Isolate the subclass name */
-        ClassName += 6;
-        sprintf(LookupString, "\t%02x  ", PciData->SubClass);
+        ClassName += strlen("C 00  ");
+        ClassEnd = strstr(ClassName, "\nC ");
+        sprintf(LookupString, "\n\t%02x  ", PciData->SubClass);
         SubClassName = strstr(ClassName, LookupString);
-        if (SubClassName)
+        if (ClassEnd && SubClassName > ClassEnd)
         {
-            /* Copy the subclass into our buffer */
-            SubClassName += 5;
-            p = strpbrk(SubClassName, "\r\n");
-            Length = p - SubClassName;
-            if (Length >= sizeof(bSubClassName)) Length = sizeof(bSubClassName) - 1;
-            strncpy(bSubClassName, SubClassName, Length);
-            bSubClassName[Length] = '\0';
+            SubClassName = NULL;
         }
+        if (!SubClassName)
+        {
+            SubClassName = ClassName;
+        }
+        else
+        {
+            SubClassName += strlen("\n\t00  ");
+        }
+        /* Copy the subclass into our buffer */
+        p = strpbrk(SubClassName, "\r\n");
+        Length = p - SubClassName;
+        if (Length >= sizeof(bSubClassName)) Length = sizeof(bSubClassName) - 1;
+        strncpy(bSubClassName, SubClassName, Length);
+        bSubClassName[Length] = '\0';
     }
 
     /* Isolate the vendor name */