]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/FwVol/FwVol.c
Fix the issue that accessing for unaligned address break IPF
[mirror_edk2.git] / MdeModulePkg / Core / Pei / FwVol / FwVol.c
index 88eb2b2a1576c6a09592f64646383114a365a6f9..d2bd6c493ef45e17877bfac9cb7d53243f51deac 100644 (file)
@@ -634,7 +634,7 @@ PeiFfsFindSectionData (
   @param PeiServices     An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
   @param SearchType      Filter to find only files of this type.\r
                          Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r
-  @param VolumeHandle    Handle of firmware volume in which to search.\r
+  @param FvHandle        Handle of firmware volume in which to search.\r
   @param FileHandle      On entry, points to the current handle from which to begin searching or NULL to start\r
                          at the beginning of the firmware volume. On exit, points the file handle of the next file\r
                          in the volume or NULL if there are no more files.\r
@@ -853,6 +853,7 @@ ProcessFvFile (
   EFI_PEI_FV_HANDLE             ParentFvHandle;\r
   EFI_FIRMWARE_VOLUME_HEADER    *FvHeader;\r
   EFI_FV_FILE_INFO              FileInfo;\r
+  UINT64                        FvLength;\r
   \r
   //\r
   // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already\r
@@ -890,7 +891,7 @@ ProcessFvFile (
   //\r
   // FvAlignment must be more than 8 bytes required by FvHeader structure.\r
   //\r
-  FvAlignment = 1 << ((FvHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);\r
+  FvAlignment = 1 << ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_ALIGNMENT) >> 16);\r
   if (FvAlignment < 8) {\r
     FvAlignment = 8;\r
   }\r
@@ -899,11 +900,12 @@ ProcessFvFile (
   // Check FvImage\r
   //\r
   if ((UINTN) FvHeader % FvAlignment != 0) {\r
-    NewFvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvHeader->FvLength), FvAlignment);\r
+    FvLength    = ReadUnaligned64 (&FvHeader->FvLength);\r
+    NewFvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32) FvLength), FvAlignment);\r
     if (NewFvBuffer == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
     }\r
-    CopyMem (NewFvBuffer, FvHeader, (UINTN) FvHeader->FvLength);\r
+    CopyMem (NewFvBuffer, FvHeader, (UINTN) FvLength);\r
     FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) NewFvBuffer;\r
   }\r
   \r