]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c
MdeModulePkg: Fix a PciBusDxe hot plug bug
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / PciBusDxe / PciOptionRomSupport.c
index 84c6f21ca33a79df56b1ac48fe0a403416abd41e..2bc4f8c5e8573a144e05ea21605d17a7479a994a 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   PCI Rom supporting funtions implementation for PCI Bus module.\r
 \r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -327,33 +327,45 @@ ContainEfiImage (
 {\r
   PCI_EXPANSION_ROM_HEADER  *RomHeader;\r
   PCI_DATA_STRUCTURE        *RomPcir;\r
+  UINT8                     Indicator;\r
 \r
+  Indicator = 0;\r
   RomHeader = RomImage;\r
   if (RomHeader == NULL) {\r
     return FALSE;\r
   }\r
-  ASSERT (RomHeader->Signature == PCI_EXPANSION_ROM_HEADER_SIGNATURE);\r
 \r
-  while ((UINT8 *) RomHeader < (UINT8 *) RomImage + RomSize) {\r
+  do {\r
     if (RomHeader->Signature != PCI_EXPANSION_ROM_HEADER_SIGNATURE) {\r
       RomHeader = (PCI_EXPANSION_ROM_HEADER *) ((UINT8 *) RomHeader + 512);\r
       continue;\r
     }\r
 \r
-    RomPcir    = (PCI_DATA_STRUCTURE *) ((UINT8 *) RomHeader + RomHeader->PcirOffset);\r
-    ASSERT (RomPcir->Signature == PCI_DATA_STRUCTURE_SIGNATURE);\r
+    //\r
+    // The PCI Data Structure must be DWORD aligned. \r
+    //\r
+    if (RomHeader->PcirOffset == 0 ||\r
+        (RomHeader->PcirOffset & 3) != 0 ||\r
+        (UINT8 *) RomHeader + RomHeader->PcirOffset + sizeof (PCI_DATA_STRUCTURE) > (UINT8 *) RomImage + RomSize) {\r
+      break;\r
+    }\r
+\r
+    RomPcir = (PCI_DATA_STRUCTURE *) ((UINT8 *) RomHeader + RomHeader->PcirOffset);\r
+    if (RomPcir->Signature != PCI_DATA_STRUCTURE_SIGNATURE) {\r
+      break;\r
+    }\r
 \r
     if (RomPcir->CodeType == PCI_CODE_TYPE_EFI_IMAGE) {\r
       return TRUE;\r
     }\r
 \r
-    RomHeader = (PCI_EXPANSION_ROM_HEADER *) ((UINT8 *) RomHeader + RomPcir->Length * 512);\r
-  }\r
+    Indicator = RomPcir->Indicator;\r
+    RomHeader = (PCI_EXPANSION_ROM_HEADER *) ((UINT8 *) RomHeader + RomPcir->ImageLength * 512);\r
+  } while (((UINT8 *) RomHeader < (UINT8 *) RomImage + RomSize) && ((Indicator & 0x80) == 0x00));\r
 \r
   return FALSE;\r
 }\r
 \r
-\r
 /**\r
   Load Option Rom image for specified PCI device.\r
 \r