]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/DxeServicesLib/DxeServicesLib.c
Clean up MdePkg source to correct some coding style issues, etc.
[mirror_edk2.git] / MdePkg / Library / DxeServicesLib / DxeServicesLib.c
index fa54c7bd01f35d631c525ba0fd0243481e273009..bd7b95c400da73ad3a097d78a5007d5545f00f20 100644 (file)
@@ -2,7 +2,7 @@
   MDE DXE Services Library provides functions that simplify the development of DXE Drivers.  \r
   These functions help access data from sections of FFS files or from file path.\r
 \r
-  Copyright (c) 2007 - 2009, Intel Corporation<BR>\r
+  Copyright (c) 2007 - 2010, Intel Corporation<BR>\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
@@ -401,7 +401,7 @@ GetSectionFromFfs (
 /**\r
   Get the image file buffer data and buffer size by its device path. \r
   \r
-  Access the file either from a firmware volume, from a file system interface, \r
+  Access the file either from a firmware volume, from a file system interface, \r
   or from the load file interface.\r
   \r
   Allocate memory to store the found image. The caller is responsible to free memory.\r
@@ -410,16 +410,15 @@ GetSectionFromFfs (
   If FileSize is NULL, then NULL is returned.\r
   If AuthenticationStatus is NULL, then NULL is returned.\r
 \r
-  @param[in]       BootPolicy \r
-                             Policy for Open Image File.If TRUE, indicates that the request \r
-                             originates from the boot manager, and that the boot manager is\r
-                             attempting to load FilePath as a boot selection. If FALSE, \r
-                             then FilePath must match an exact file to be loaded.\r
-  @param[in]       FilePath  Pointer to the device path of the file that is absracted to the file buffer.\r
-  @param[out]      FileSize  Pointer to the size of the abstracted file buffer.\r
-  @param[out]      AuthenticationStatus   \r
-                             Pointer to a caller-allocated UINT32 in which\r
-                             the authentication status is returned.\r
+  @param[in]       BootPolicy           Policy for Open Image File.If TRUE, indicates that the request \r
+                                        originates from the boot manager, and that the boot manager is\r
+                                        attempting to load FilePath as a boot selection. If FALSE, \r
+                                        then FilePath must match an exact file to be loaded.\r
+  @param[in]       FilePath             Pointer to the device path of the file that is absracted to\r
+                                        the file buffer.\r
+  @param[out]      FileSize             Pointer to the size of the abstracted file buffer.\r
+  @param[out]      AuthenticationStatus Pointer to a caller-allocated UINT32 in which the authentication\r
+                                        status is returned.\r
 \r
   @retval NULL   File is NULL, or FileSize is NULL. Or the file can't be found.\r
   @retval other  The abstracted file buffer. The caller is responsible to free memory.\r
@@ -435,6 +434,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 +462,7 @@ GetFileBufferByFilePath (
   //\r
   // Init local variable\r
   //\r
+  TempDevicePathNode  = NULL;\r
   FvNameGuid          = NULL;\r
   FileInfo            = NULL;\r
   FileHandle          = NULL;\r
@@ -544,11 +545,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
@@ -603,7 +616,7 @@ GetFileBufferByFilePath (
             }\r
           }\r
           \r
-          if (!EFI_ERROR (Status)) {\r
+          if (!EFI_ERROR (Status) && (FileInfo != NULL)) {\r
             //\r
             // Allocate space for the file\r
             //\r
@@ -620,7 +633,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 +641,7 @@ GetFileBufferByFilePath (
         if (FileHandle != NULL) {\r
           FileHandle->Close (FileHandle);\r
         }\r
+        FreePool (TempDevicePathNode);\r
       }\r
     }\r
     goto Finish;\r
@@ -662,7 +676,7 @@ GetFileBufferByFilePath (
             Status = LoadFile2->LoadFile (\r
                                  LoadFile2,\r
                                  DevicePathNode,\r
-                                 BootPolicy,\r
+                                 FALSE,\r
                                  &ImageBufferSize,\r
                                  ImageBuffer\r
                                  );\r