[FREELDR]
authorThomas Faber <thomas.faber@reactos.org>
Sat, 30 Aug 2014 10:59:25 +0000 (10:59 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Sat, 30 Aug 2014 10:59:25 +0000 (10:59 +0000)
- Improve GetPciIrqRoutingTable. Patch by Sergey Chernov (serrox at ya dot ru), small modifications by me.
CORE-8440

svn path=/trunk/; revision=63985

reactos/boot/freeldr/freeldr/arch/i386/hwpci.c

index 09a9e8b..4154951 100644 (file)
@@ -41,6 +41,14 @@ GetPciIrqRoutingTable(VOID)
         {
             TRACE("Found signature\n");
 
         {
             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++)
             Ptr = (PUCHAR)Table;
             Sum = 0;
             for (i = 0; i < Table->TableSize; i++)
@@ -50,18 +58,20 @@ GetPciIrqRoutingTable(VOID)
 
             if ((Sum & 0xFF) != 0)
             {
 
             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);
     }
 
         }
 
         Table = (PPCI_IRQ_ROUTING_TABLE)((ULONG_PTR)Table + 0x10);
     }
 
+    ERR("No valid routing table found!\n");
+
     return NULL;
 }
 
     return NULL;
 }