Index: usr.sbin/efibootmgr/efibootmgr.c =================================================================== --- usr.sbin/efibootmgr/efibootmgr.c +++ usr.sbin/efibootmgr/efibootmgr.c @@ -737,6 +737,7 @@ return 0; } +#define EFIDP_MAX(dp, edp) ((uintptr_t)edp - (uintptr_t)dp) static void print_loadopt_str(uint8_t *data, size_t datalen) @@ -779,11 +780,10 @@ * optlen = ep - walker; */ indent = 1; - while (dp < edp) { - efidp_format_device_path(buf, sizeof(buf), dp, - (intptr_t)(void *)edp - (intptr_t)(void *)dp); + while (dp < edp && EFIDP_MAX(dp, edp) > sizeof(efidp_header)) { + efidp_format_device_path(buf, sizeof(buf), dp, EFIDP_MAX(dp, edp)); printf("%*s%s\n", indent, "", buf); - indent = 10 + len + 1; + indent = 11 + len + 1; rv = efivar_device_path_to_unix_path(dp, &dev, &relpath, &abspath); if (rv == 0) { printf("%*s%s:%s %s\n", indent + 4, "", dev, relpath, abspath);