Implement efi_devpath_match_node

Returns true if the first node pointed to by devpath1 is identical to
the first node pointed to by devpath2, with care taken to not read
past the end of the valid parts of either devpath1 or
devpath2. Otherwise, returns false.

Sponsored by: Netflix
This commit is contained in:
Warner Losh 2018-07-23 20:36:45 +00:00
parent 3ef81aa0f5
commit 13850b362f
2 changed files with 21 additions and 12 deletions

View File

@ -85,6 +85,7 @@ EFI_HANDLE efi_devpath_handle(EFI_DEVICE_PATH *);
EFI_DEVICE_PATH *efi_devpath_last_node(EFI_DEVICE_PATH *);
EFI_DEVICE_PATH *efi_devpath_trim(EFI_DEVICE_PATH *);
bool efi_devpath_match(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *);
bool efi_devpath_match_node(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *);
bool efi_devpath_is_prefix(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *);
CHAR16 *efi_devpath_name(EFI_DEVICE_PATH *);
void efi_free_devpath_name(CHAR16 *);

View File

@ -140,25 +140,33 @@ efi_devpath_handle(EFI_DEVICE_PATH *devpath)
}
bool
efi_devpath_match(EFI_DEVICE_PATH *devpath1, EFI_DEVICE_PATH *devpath2)
efi_devpath_match_node(EFI_DEVICE_PATH *devpath1, EFI_DEVICE_PATH *devpath2)
{
size_t len;
if (devpath1 == NULL || devpath2 == NULL)
return (false);
if (DevicePathType(devpath1) != DevicePathType(devpath2) ||
DevicePathSubType(devpath1) != DevicePathSubType(devpath2))
return (false);
len = DevicePathNodeLength(devpath1);
if (len != DevicePathNodeLength(devpath2))
return (false);
if (memcmp(devpath1, devpath2, len) != 0)
return (false);
return (true);
}
bool
efi_devpath_match(EFI_DEVICE_PATH *devpath1, EFI_DEVICE_PATH *devpath2)
{
if (devpath1 == NULL || devpath2 == NULL)
return (false);
while (true) {
if (DevicePathType(devpath1) != DevicePathType(devpath2) ||
DevicePathSubType(devpath1) != DevicePathSubType(devpath2))
return (false);
len = DevicePathNodeLength(devpath1);
if (len != DevicePathNodeLength(devpath2))
return (false);
if (memcmp(devpath1, devpath2, len) != 0)
return (false);
if (!efi_devpath_match_node(devpath1, devpath2))
return false;
if (IsDevicePathEnd(devpath1))
break;
devpath1 = NextDevicePathNode(devpath1);