Fix pointer arithmetic

Pointer math to find the size in bytes only works with char types.
Use correct pointer math to determine if we have enough of a header to
look at or not.

MFC After: 3 days
X-MFX-With: r339800
Noticed by: jhb@
Sponsored by: Netflix, Inc
This commit is contained in:
imp 2018-10-26 23:44:50 +00:00
parent 26af2aca45
commit 06a9c917f2

View File

@ -298,6 +298,8 @@ fix_dosisms(char *p)
}
}
#define SIZE(dp, edp) (size_t)((intptr_t)(void *)edp - (intptr_t)(void *)dp)
enum { BOOT_INFO_OK = 0, BAD_CHOICE = 1, NOT_SPECIFIC = 2 };
static int
match_boot_info(EFI_LOADED_IMAGE *img __unused, char *boot_info, size_t bisz)
@ -349,7 +351,7 @@ match_boot_info(EFI_LOADED_IMAGE *img __unused, char *boot_info, size_t bisz)
edp = (EFI_DEVICE_PATH *)(walker + fplen);
if ((char *)edp > ep)
return NOT_SPECIFIC;
while (dp < edp && (size_t)(edp - dp) > sizeof(EFI_DEVICE_PATH)) {
while (dp < edp && SIZE(dp, edp) > sizeof(EFI_DEVICE_PATH)) {
text = efi_devpath_name(dp);
if (text != NULL) {
printf(" BootInfo Path: %S\n", text);