Sync with trunk revision 64099.
[reactos.git] / boot / freeldr / freeldr / arch / i386 / hwpci.c
index 09a9e8b..4154951 100644 (file)
@@ -41,6 +41,14 @@ GetPciIrqRoutingTable(VOID)
         {
             TRACE("Found signature\n");
 
+            if (Table->TableSize < FIELD_OFFSET(PCI_IRQ_ROUTING_TABLE, Slot) ||
+                Table->TableSize % 16 != 0)
+            {
+                ERR("Invalid routing table size (%u) at %p. Continue searching...\n", Table->TableSize, Table);
+                Table = (PPCI_IRQ_ROUTING_TABLE)((ULONG_PTR)Table + 0x10);
+                continue;
+            }
+
             Ptr = (PUCHAR)Table;
             Sum = 0;
             for (i = 0; i < Table->TableSize; i++)
@@ -50,18 +58,20 @@ GetPciIrqRoutingTable(VOID)
 
             if ((Sum & 0xFF) != 0)
             {
-                ERR("Invalid routing table\n");
-                return NULL;
+                ERR("Invalid routing table checksum (%#lx) at %p. Continue searching...\n", Sum & 0xFF, Table);
+            }
+            else
+            {
+                TRACE("Valid checksum\n");
+                return Table;
             }
-
-            TRACE("Valid checksum\n");
-
-            return Table;
         }
 
         Table = (PPCI_IRQ_ROUTING_TABLE)((ULONG_PTR)Table + 0x10);
     }
 
+    ERR("No valid routing table found!\n");
+
     return NULL;
 }