mirror of https://github.com/acidanthera/audk.git
[Description]
Duplicate the device path prior to the access to it [Impaction] directly access the device path may cause an exception when the device path includes some unaligned device path nodes [Reference Info] In the case of ISCSI, there is a situation that the device path may consists of some unaligned device path node. it causes the unaligned exception when we access the node. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4905 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
d63e4c2308
commit
1564e9ac2c
|
@ -1,6 +1,6 @@
|
||||||
/*++
|
/*++
|
||||||
|
|
||||||
Copyright (c) 2006 - 2007, Intel Corporation
|
Copyright (c) 2006 - 2008, Intel Corporation
|
||||||
All rights reserved. This program and the accompanying materials
|
All rights reserved. This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -83,7 +83,9 @@ Returns:
|
||||||
EFI_FILE_INFO *FileInfo;
|
EFI_FILE_INFO *FileInfo;
|
||||||
UINTN FileInfoSize;
|
UINTN FileInfoSize;
|
||||||
EFI_GUID *NameGuid;
|
EFI_GUID *NameGuid;
|
||||||
|
FILEPATH_DEVICE_PATH *OriginalFilePathNode;
|
||||||
|
|
||||||
|
OriginalFilePathNode = NULL;
|
||||||
*AuthenticationStatus = 0;
|
*AuthenticationStatus = 0;
|
||||||
ZeroMem (ImageFileHandle, sizeof (IMAGE_FILE_HANDLE));
|
ZeroMem (ImageFileHandle, sizeof (IMAGE_FILE_HANDLE));
|
||||||
ImageFileHandle->Signature = IMAGE_FILE_HANDLE_SIGNATURE;
|
ImageFileHandle->Signature = IMAGE_FILE_HANDLE_SIGNATURE;
|
||||||
|
@ -187,41 +189,57 @@ Returns:
|
||||||
//
|
//
|
||||||
Status = Volume->OpenVolume (Volume, &FileHandle);
|
Status = Volume->OpenVolume (Volume, &FileHandle);
|
||||||
if (!EFI_ERROR (Status)) {
|
if (!EFI_ERROR (Status)) {
|
||||||
|
|
||||||
//
|
//
|
||||||
// Parse each MEDIA_FILEPATH_DP node. There may be more than one, since the
|
// Duplicate the device path to avoid the access to unaligned device path node.
|
||||||
// directory information and filename can be seperate. The goal is to inch
|
// Because the device path consists of one or more FILE PATH MEDIA DEVICE PATH
|
||||||
// our way down each device path node and close the previous node
|
// nodes, It assures the fields in device path nodes are 2 byte aligned.
|
||||||
//
|
//
|
||||||
while (!IsDevicePathEnd (&FilePathNode->Header)) {
|
FilePathNode = (FILEPATH_DEVICE_PATH *)CoreDuplicateDevicePath((EFI_DEVICE_PATH_PROTOCOL *)(UINTN)FilePathNode);
|
||||||
if (DevicePathType (&FilePathNode->Header) != MEDIA_DEVICE_PATH ||
|
if (FilePathNode == NULL) {
|
||||||
DevicePathSubType (&FilePathNode->Header) != MEDIA_FILEPATH_DP) {
|
FileHandle->Close (FileHandle);
|
||||||
Status = EFI_UNSUPPORTED;
|
Status = EFI_OUT_OF_RESOURCES;
|
||||||
}
|
} else {
|
||||||
|
OriginalFilePathNode = FilePathNode;
|
||||||
if (EFI_ERROR (Status)) {
|
|
||||||
//
|
|
||||||
// Exit loop on Error
|
|
||||||
//
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
LastHandle = FileHandle;
|
|
||||||
FileHandle = NULL;
|
|
||||||
Status = LastHandle->Open (
|
|
||||||
LastHandle,
|
|
||||||
&FileHandle,
|
|
||||||
FilePathNode->PathName,
|
|
||||||
EFI_FILE_MODE_READ,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Close the previous node
|
// 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
|
||||||
//
|
//
|
||||||
LastHandle->Close (LastHandle);
|
while (!IsDevicePathEnd (&FilePathNode->Header)) {
|
||||||
|
if (DevicePathType (&FilePathNode->Header) != MEDIA_DEVICE_PATH ||
|
||||||
|
DevicePathSubType (&FilePathNode->Header) != MEDIA_FILEPATH_DP) {
|
||||||
|
Status = EFI_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
FilePathNode = (FILEPATH_DEVICE_PATH *) NextDevicePathNode (&FilePathNode->Header);
|
if (EFI_ERROR (Status)) {
|
||||||
|
//
|
||||||
|
// Exit loop on Error
|
||||||
|
//
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
LastHandle = FileHandle;
|
||||||
|
FileHandle = NULL;
|
||||||
|
|
||||||
|
Status = LastHandle->Open (
|
||||||
|
LastHandle,
|
||||||
|
&FileHandle,
|
||||||
|
FilePathNode->PathName,
|
||||||
|
EFI_FILE_MODE_READ,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Close the previous node
|
||||||
|
//
|
||||||
|
LastHandle->Close (LastHandle);
|
||||||
|
|
||||||
|
FilePathNode = (FILEPATH_DEVICE_PATH *) NextDevicePathNode (&FilePathNode->Header);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// Free the allocated memory pool
|
||||||
|
//
|
||||||
|
CoreFreePool(OriginalFilePathNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EFI_ERROR (Status)) {
|
if (!EFI_ERROR (Status)) {
|
||||||
|
|
Loading…
Reference in New Issue