Harden BlpDuplicateDevicePath against malformed device paths
This commit is contained in:
parent
b0aabf96b8
commit
7fce778ee4
@ -927,17 +927,25 @@ BlpDuplicateDevicePath(IN PEFI_DEVICE_PATH_PROTOCOL DevicePath)
|
|||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINT Length = 0;
|
UINT Length = 0;
|
||||||
|
|
||||||
|
/* Check if the input device path is NULL */
|
||||||
|
if(!DevicePath)
|
||||||
|
{
|
||||||
|
/* Nothing to duplicate */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Start iterating from the beginning of the device path */
|
||||||
DevicePathNode = DevicePath;
|
DevicePathNode = DevicePath;
|
||||||
|
|
||||||
/* Get the device path length */
|
/* Get the device path length */
|
||||||
while(TRUE)
|
while(TRUE)
|
||||||
{
|
{
|
||||||
Length += *(PUSHORT)DevicePath->Length;
|
Length += *(PUSHORT)DevicePathNode->Length;
|
||||||
if(DevicePathNode->Type == EFI_END_DEVICE_PATH)
|
if(DevicePathNode->Type == EFI_END_DEVICE_PATH)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
DevicePathNode = (PEFI_DEVICE_PATH_PROTOCOL)((PUCHAR)DevicePathNode + *(PUSHORT)DevicePath->Length);
|
DevicePathNode = (PEFI_DEVICE_PATH_PROTOCOL)((PUCHAR)DevicePathNode + *(PUSHORT)DevicePathNode->Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check length */
|
/* Check length */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user