]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c
Add DiskIo2 protocol definition to MdePkg.
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / PartitionDxe / Gpt.c
index a3910041a3daaffdf0bfe245bf7d49de8904bec3..35860515c13b9da3284b2a5f0d5c57cad2032016 100644 (file)
@@ -13,7 +13,7 @@
   PartitionValidGptTable(), PartitionCheckGptEntry() routine will accept disk\r
   partition content and validate the GPT table and GPT entry.\r
 \r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2013, 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
@@ -184,6 +184,7 @@ PartitionSetCrc (
   @param[in]  This       Calling context.\r
   @param[in]  Handle     Parent Handle.\r
   @param[in]  DiskIo     Parent DiskIo interface.\r
+  @param[in]  DiskIo2    Parent DiskIo2 interface.\r
   @param[in]  BlockIo    Parent BlockIo interface.\r
   @param[in]  BlockIo2   Parent BlockIo2 interface.\r
   @param[in]  DevicePath Parent Device Path.\r
@@ -198,6 +199,7 @@ PartitionInstallGptChildHandles (
   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
   IN  EFI_HANDLE                   Handle,\r
   IN  EFI_DISK_IO_PROTOCOL         *DiskIo,\r
+  IN  EFI_DISK_IO2_PROTOCOL        *DiskIo2,\r
   IN  EFI_BLOCK_IO_PROTOCOL        *BlockIo,\r
   IN  EFI_BLOCK_IO2_PROTOCOL       *BlockIo2,\r
   IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePath\r
@@ -307,7 +309,7 @@ PartitionInstallGptChildHandles (
     DEBUG ((EFI_D_INFO, " Valid primary and !Valid backup partition table\n"));\r
     DEBUG ((EFI_D_INFO, " Restore backup partition table by the primary\n"));\r
     if (!PartitionRestoreGptTable (BlockIo, DiskIo, PrimaryHeader)) {\r
-      DEBUG ((EFI_D_INFO, " Restore  backup partition table error\n"));\r
+      DEBUG ((EFI_D_INFO, " Restore backup partition table error\n"));\r
     }\r
 \r
     if (PartitionValidGptTable (BlockIo, DiskIo, PrimaryHeader->AlternateLBA, BackupHeader)) {\r
@@ -400,6 +402,7 @@ PartitionInstallGptChildHandles (
                This,\r
                Handle,\r
                DiskIo,\r
+               DiskIo2,\r
                BlockIo,\r
                BlockIo2,\r
                DevicePath,\r
@@ -487,13 +490,22 @@ PartitionValidGptTable (
 \r
   if ((PartHdr->Header.Signature != EFI_PTAB_HEADER_ID) ||\r
       !PartitionCheckCrc (BlockSize, &PartHdr->Header) ||\r
-      PartHdr->MyLBA != Lba\r
+      PartHdr->MyLBA != Lba ||\r
+      (PartHdr->SizeOfPartitionEntry < sizeof (EFI_PARTITION_ENTRY))\r
       ) {\r
     DEBUG ((EFI_D_INFO, "Invalid efi partition table header\n"));\r
     FreePool (PartHdr);\r
     return FALSE;\r
   }\r
 \r
+  //\r
+  // Ensure the NumberOfPartitionEntries * SizeOfPartitionEntry doesn't overflow.\r
+  //\r
+  if (PartHdr->NumberOfPartitionEntries > DivU64x32 (MAX_UINTN, PartHdr->SizeOfPartitionEntry)) {\r
+    FreePool (PartHdr);\r
+    return FALSE;\r
+  }\r
+\r
   CopyMem (PartHeader, PartHdr, sizeof (EFI_PARTITION_TABLE_HEADER));\r
   if (!PartitionCheckGptEntryArrayCRC (BlockIo, DiskIo, PartHeader)) {\r
     FreePool (PartHdr);\r