]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Image/ImageFile.c
[Description]
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Image / ImageFile.c
index 5d8293a7348ac0646adc6931b8e15caea177e925..b9c8c657b82dceee87cab618f44709c5df83195b 100644 (file)
@@ -1,6 +1,6 @@
 /*++\r
 \r
-Copyright (c) 2006 - 2007, Intel Corporation\r
+Copyright (c) 2006 - 2008, 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
@@ -83,7 +83,9 @@ Returns:
   EFI_FILE_INFO                     *FileInfo;\r
   UINTN                             FileInfoSize;\r
   EFI_GUID                          *NameGuid;\r
+  FILEPATH_DEVICE_PATH              *OriginalFilePathNode;\r
 \r
+  OriginalFilePathNode = NULL;\r
   *AuthenticationStatus = 0;\r
   ZeroMem (ImageFileHandle, sizeof (IMAGE_FILE_HANDLE));\r
   ImageFileHandle->Signature = IMAGE_FILE_HANDLE_SIGNATURE;\r
@@ -187,41 +189,57 @@ Returns:
     //\r
     Status = Volume->OpenVolume (Volume, &FileHandle);\r
     if (!EFI_ERROR (Status)) {\r
-\r
       //\r
-      // Parse each MEDIA_FILEPATH_DP node. There may be more than one, since the\r
-      //  directory information and filename can be seperate. The goal is to inch\r
-      //  our way down each device path node and close the previous node\r
+      // Duplicate the device path to avoid the access to unaligned device path node.\r
+      // Because the device path consists of one or more FILE PATH MEDIA DEVICE PATH\r
+      // nodes, It assures the fields in device path nodes are 2 byte aligned. \r
       //\r
-      while (!IsDevicePathEnd (&FilePathNode->Header)) {\r
-        if (DevicePathType (&FilePathNode->Header) != MEDIA_DEVICE_PATH ||\r
-            DevicePathSubType (&FilePathNode->Header) != MEDIA_FILEPATH_DP) {\r
-          Status = EFI_UNSUPPORTED;\r
-        }\r
+      FilePathNode = (FILEPATH_DEVICE_PATH *)CoreDuplicateDevicePath((EFI_DEVICE_PATH_PROTOCOL *)(UINTN)FilePathNode);\r
+      if (FilePathNode == NULL) {\r
+        FileHandle->Close (FileHandle);\r
+        Status = EFI_OUT_OF_RESOURCES;\r
+      } else {\r
+        OriginalFilePathNode = FilePathNode;\r
+        //\r
+        // Parse each MEDIA_FILEPATH_DP node. There may be more than one, since the\r
+        // directory information and filename can be seperate. The goal is to inch\r
+        // our way down each device path node and close the previous node\r
+        //\r
+        while (!IsDevicePathEnd (&FilePathNode->Header)) {\r
+          if (DevicePathType (&FilePathNode->Header) != MEDIA_DEVICE_PATH ||\r
+              DevicePathSubType (&FilePathNode->Header) != MEDIA_FILEPATH_DP) {\r
+            Status = EFI_UNSUPPORTED;\r
+          }\r
+\r
+          if (EFI_ERROR (Status)) {\r
+            //\r
+            // Exit loop on Error\r
+            //\r
+            break;\r
+          }\r
+\r
+          LastHandle = FileHandle;\r
+          FileHandle = NULL;\r
+\r
+          Status = LastHandle->Open (\r
+                                LastHandle,\r
+                                &FileHandle,\r
+                                FilePathNode->PathName,\r
+                                EFI_FILE_MODE_READ,\r
+                                0\r
+                                );\r
 \r
-        if (EFI_ERROR (Status)) {\r
           //\r
-          // Exit loop on Error\r
+          // Close the previous node\r
           //\r
-          break;\r
-        }\r
-\r
-        LastHandle = FileHandle;\r
-        FileHandle = NULL;\r
-        Status = LastHandle->Open (\r
-                              LastHandle,\r
-                              &FileHandle,\r
-                              FilePathNode->PathName,\r
-                              EFI_FILE_MODE_READ,\r
-                              0\r
-                              );\r
+          LastHandle->Close (LastHandle);\r
 \r
+          FilePathNode = (FILEPATH_DEVICE_PATH *) NextDevicePathNode (&FilePathNode->Header);\r
+        }\r
         //\r
-        // Close the previous node\r
+        // Free the allocated memory pool \r
         //\r
-        LastHandle->Close (LastHandle);\r
-\r
-        FilePathNode = (FILEPATH_DEVICE_PATH *) NextDevicePathNode (&FilePathNode->Header);\r
+        CoreFreePool(OriginalFilePathNode);\r
       }\r
 \r
       if (!EFI_ERROR (Status)) {\r