]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkModulePkg/Universal/Disk/Partition/Dxe/Mbr.c
Fix a critical bug: When reading block succeeds but detecting MBR fails, it should...
[mirror_edk2.git] / EdkModulePkg / Universal / Disk / Partition / Dxe / Mbr.c
index 8dd0b4b497d53b5c8e2ebafbe188d584b190ecb4..d71698c82673dcb08641b05b5482c4c4eca4f755 100644 (file)
@@ -1,6 +1,6 @@
 /*++\r
 \r
-Copyright (c) 2006, Intel Corporation                                                         \r
+Copyright (c) 2006 - 2007, Intel Corporation                                                         \r
 All rights reserved. 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
@@ -162,10 +162,13 @@ Returns:
                       BlockIo->Media->BlockSize,\r
                       Mbr\r
                       );\r
-  if (EFI_ERROR (Status) || !PartitionValidMbr (Mbr, BlockIo->Media->LastBlock)) {\r
+  if (EFI_ERROR (Status)) {\r
     Found = Status;\r
     goto Done;\r
   }\r
+  if (!PartitionValidMbr (Mbr, BlockIo->Media->LastBlock)) {\r
+    goto Done;\r
+  }\r
   //\r
   // We have a valid mbr - add each partition\r
   //\r
@@ -184,7 +187,7 @@ Returns:
     if (DevicePathType (LastDevicePathNode) == MEDIA_DEVICE_PATH &&\r
         DevicePathSubType (LastDevicePathNode) == MEDIA_HARDDRIVE_DP\r
         ) {\r
-      gBS->CopyMem (&ParentHdDev, LastDevicePathNode, sizeof (ParentHdDev));\r
+      CopyMem (&ParentHdDev, LastDevicePathNode, sizeof (ParentHdDev));\r
     } else {\r
       LastDevicePathNode = NULL;\r
     }\r
@@ -276,8 +279,8 @@ Returns:
       HdDev.PartitionNumber = PartitionNumber ++;\r
       HdDev.PartitionStart  = UNPACK_UINT32 (Mbr->Partition[0].StartingLBA) + ExtMbrStartingLba + ParentHdDev.PartitionStart;\r
       HdDev.PartitionSize   = UNPACK_UINT32 (Mbr->Partition[0].SizeInLBA);\r
-      if (HdDev.PartitionStart + HdDev.PartitionSize - 1 >=\r
-            ParentHdDev.PartitionStart + ParentHdDev.PartitionSize) {\r
+      if ((HdDev.PartitionStart + HdDev.PartitionSize - 1 >= ParentHdDev.PartitionStart + ParentHdDev.PartitionSize) ||\r
+          (HdDev.PartitionStart <= ParentHdDev.PartitionStart)) {\r
         break;\r
       }\r
 \r
@@ -319,7 +322,7 @@ Returns:
   }\r
 \r
 Done:\r
-  gBS->FreePool (Mbr);\r
+  FreePool (Mbr);\r
 \r
   return Found;\r
 }\r