]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c
MdeModulePkg/NonDiscoverable: fix memory override bug
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / NonDiscoverablePciDeviceDxe / NonDiscoverablePciDeviceIo.c
index 1ffbdfa5f6d4a5105b5ccb266e0db01a2d525c07..0e42ae4bf6ecd87175e87bab67dfb3812aee895e 100644 (file)
@@ -465,6 +465,11 @@ PciIoPciRead (
   Address = (UINT8 *)&Dev->ConfigSpace + Offset;\r
   Length = Count << ((UINTN)Width & 0x3);\r
 \r
+  if (Offset >= sizeof (Dev->ConfigSpace)) {\r
+    ZeroMem (Buffer, Length);\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
   if (Offset + Length > sizeof (Dev->ConfigSpace)) {\r
     //\r
     // Read all zeroes for config space accesses beyond the first\r
@@ -598,7 +603,7 @@ CoherentPciIoMap (
   //\r
   Dev = NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This);\r
   if ((Dev->Attributes & EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE) == 0 &&\r
-      (UINTN)HostAddress + *NumberOfBytes > SIZE_4GB) {\r
+      (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress + *NumberOfBytes > SIZE_4GB) {\r
 \r
     //\r
     // Bounce buffering is not possible for consistent mappings\r
@@ -1006,7 +1011,7 @@ NonCoherentPciIoMap (
   // a bounce buffer and copy over the data in case HostAddress >= 4 GB.\r
   //\r
   Bounce = ((Dev->Attributes & EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE) == 0 &&\r
-            (UINTN)HostAddress + *NumberOfBytes > SIZE_4GB);\r
+            (EFI_PHYSICAL_ADDRESS)(UINTN)HostAddress + *NumberOfBytes > SIZE_4GB);\r
 \r
   if (!Bounce) {\r
     switch (Operation) {\r
@@ -1300,7 +1305,8 @@ PciIoGetBarAttributes (
   )\r
 {\r
   NON_DISCOVERABLE_PCI_DEVICE       *Dev;\r
-  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor, *BarDesc;\r
+  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor;\r
+  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *BarDesc;\r
   EFI_ACPI_END_TAG_DESCRIPTOR       *End;\r
   EFI_STATUS                        Status;\r
 \r