summaryrefslogtreecommitdiff
path: root/MdePkg/Library
diff options
context:
space:
mode:
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>2009-12-01 10:29:39 +0000
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>2009-12-01 10:29:39 +0000
commit95dd343a4be064f3fa32d55da41fb367369e6828 (patch)
treeda694afc74a1d0a439df677958f43bb1f4df9125 /MdePkg/Library
parenta13df02ed548b9bf1adf31a8822d4c331dc54b20 (diff)
downloadedk2-95dd343a4be064f3fa32d55da41fb367369e6828.zip
edk2-95dd343a4be064f3fa32d55da41fb367369e6828.tar.gz
edk2-95dd343a4be064f3fa32d55da41fb367369e6828.tar.bz2
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
Diffstat (limited to 'MdePkg/Library')
-rw-r--r--MdePkg/Library/DxeServicesLib/DxeServicesLib.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/MdePkg/Library/DxeServicesLib/DxeServicesLib.c b/MdePkg/Library/DxeServicesLib/DxeServicesLib.c
index fa54c7b..107bf4b 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;
@@ -545,10 +547,22 @@ 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;