From 95dd343a4be064f3fa32d55da41fb367369e6828 Mon Sep 17 00:00:00 2001 From: lgao4 Date: Tue, 1 Dec 2009 10:29:39 +0000 Subject: [PATCH] Make MEDIA DEVICE PATH on 2 byte aligned to avoid the access to unaligned device path node. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9503 6f19259b-4bc3-4df7-8a09-765794883524 --- MdePkg/Library/DxeServicesLib/DxeServicesLib.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/MdePkg/Library/DxeServicesLib/DxeServicesLib.c b/MdePkg/Library/DxeServicesLib/DxeServicesLib.c index fa54c7bd01..107bf4bd62 100644 --- a/MdePkg/Library/DxeServicesLib/DxeServicesLib.c +++ b/MdePkg/Library/DxeServicesLib/DxeServicesLib.c @@ -435,6 +435,7 @@ GetFileBufferByFilePath ( { EFI_DEVICE_PATH_PROTOCOL *DevicePathNode; EFI_DEVICE_PATH_PROTOCOL *OrigDevicePathNode; + EFI_DEVICE_PATH_PROTOCOL *TempDevicePathNode; EFI_HANDLE Handle; EFI_GUID *FvNameGuid; EFI_FIRMWARE_VOLUME2_PROTOCOL *FwVol; @@ -462,6 +463,7 @@ GetFileBufferByFilePath ( // // Init local variable // + TempDevicePathNode = NULL; FvNameGuid = NULL; FileInfo = NULL; FileHandle = NULL; @@ -544,11 +546,23 @@ GetFileBufferByFilePath ( // Status = Volume->OpenVolume (Volume, &FileHandle); if (!EFI_ERROR (Status)) { + // + // Duplicate the device path to avoid the access to unaligned device path node. + // Because the device path consists of one or more FILE PATH MEDIA DEVICE PATH + // nodes, It assures the fields in device path nodes are 2 byte aligned. + // + TempDevicePathNode = DuplicateDevicePath (DevicePathNode); + if (TempDevicePathNode == NULL) { + FileHandle->Close (FileHandle); + Status = EFI_OUT_OF_RESOURCES; + goto Finish; + } // // Parse each MEDIA_FILEPATH_DP node. There may be more than one, since the // directory information and filename can be seperate. The goal is to inch // our way down each device path node and close the previous node // + DevicePathNode = TempDevicePathNode; while (!IsDevicePathEnd (DevicePathNode) && !EFI_ERROR (Status)) { if (DevicePathType (DevicePathNode) != MEDIA_DEVICE_PATH || DevicePathSubType (DevicePathNode) != MEDIA_FILEPATH_DP) { @@ -620,7 +634,7 @@ GetFileBufferByFilePath ( } } // - // Close the file and Free FileInfo since we are done + // Close the file and Free FileInfo and TempDevicePathNode since we are done // if (FileInfo != NULL) { FreePool (FileInfo); @@ -628,6 +642,7 @@ GetFileBufferByFilePath ( if (FileHandle != NULL) { FileHandle->Close (FileHandle); } + FreePool (TempDevicePathNode); } } goto Finish; -- 2.39.2