]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Make MEDIA DEVICE PATH on 2 byte aligned to avoid the access to unaligned device...
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 1 Dec 2009 10:29:39 +0000 (10:29 +0000)
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 1 Dec 2009 10:29:39 +0000 (10:29 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9503 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Library/DxeServicesLib/DxeServicesLib.c

index fa54c7bd01f35d631c525ba0fd0243481e273009..107bf4bd62790507bce991127d27691aca7e6cd5 100644 (file)
@@ -435,6 +435,7 @@ GetFileBufferByFilePath (
 {\r
   EFI_DEVICE_PATH_PROTOCOL          *DevicePathNode;\r
   EFI_DEVICE_PATH_PROTOCOL          *OrigDevicePathNode;\r
+  EFI_DEVICE_PATH_PROTOCOL          *TempDevicePathNode;\r
   EFI_HANDLE                        Handle;\r
   EFI_GUID                          *FvNameGuid;\r
   EFI_FIRMWARE_VOLUME2_PROTOCOL     *FwVol;\r
@@ -462,6 +463,7 @@ GetFileBufferByFilePath (
   //\r
   // Init local variable\r
   //\r
+  TempDevicePathNode  = NULL;\r
   FvNameGuid          = NULL;\r
   FileInfo            = NULL;\r
   FileHandle          = NULL;\r
@@ -544,11 +546,23 @@ GetFileBufferByFilePath (
       //\r
       Status = Volume->OpenVolume (Volume, &FileHandle);\r
       if (!EFI_ERROR (Status)) {\r
+        //\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
+        TempDevicePathNode = DuplicateDevicePath (DevicePathNode);\r
+        if (TempDevicePathNode == NULL) {\r
+          FileHandle->Close (FileHandle);\r
+          Status = EFI_OUT_OF_RESOURCES;\r
+          goto Finish;\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
         //\r
+        DevicePathNode = TempDevicePathNode;\r
         while (!IsDevicePathEnd (DevicePathNode) && !EFI_ERROR (Status)) {\r
           if (DevicePathType (DevicePathNode) != MEDIA_DEVICE_PATH ||\r
               DevicePathSubType (DevicePathNode) != MEDIA_FILEPATH_DP) {\r
@@ -620,7 +634,7 @@ GetFileBufferByFilePath (
           }\r
         }\r
         //\r
-        // Close the file and Free FileInfo since we are done\r
+        // Close the file and Free FileInfo and TempDevicePathNode since we are done\r
         // \r
         if (FileInfo != NULL) {\r
           FreePool (FileInfo);\r
@@ -628,6 +642,7 @@ GetFileBufferByFilePath (
         if (FileHandle != NULL) {\r
           FileHandle->Close (FileHandle);\r
         }\r
+        FreePool (TempDevicePathNode);\r
       }\r
     }\r
     goto Finish;\r