git: bf87d4a4bfaa - main - efibootmgr: fix potential endless loop with -v

From: Andriy Gapon <avg_at_FreeBSD.org>
Date: Sun, 28 Jan 2024 13:20:58 UTC
The branch main has been updated by avg:

URL: https://cgit.FreeBSD.org/src/commit/?id=bf87d4a4bfaa86e97079754e93fe14595adf07c5

commit bf87d4a4bfaa86e97079754e93fe14595adf07c5
Author:     Andriy Gapon <avg@FreeBSD.org>
AuthorDate: 2022-10-25 21:10:39 +0000
Commit:     Andriy Gapon <avg@FreeBSD.org>
CommitDate: 2024-01-28 13:20:29 +0000

    efibootmgr: fix potential endless loop with -v
    
    I observed the problem on a system with fairly old and, apparently,
    buggy EFI implementation.  A list of boot devices had an invalid
    trailing entry.  efidp_size() for that entry returned zero, which means
    that the code got stuck looping on that entry.
---
 usr.sbin/efibootmgr/efibootmgr.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/usr.sbin/efibootmgr/efibootmgr.c b/usr.sbin/efibootmgr/efibootmgr.c
index 4a6a7fdfec39..7bcb4674586b 100644
--- a/usr.sbin/efibootmgr/efibootmgr.c
+++ b/usr.sbin/efibootmgr/efibootmgr.c
@@ -790,6 +790,8 @@ print_loadopt_str(uint8_t *data, size_t datalen)
 	 */
 	indent = 1;
 	while (dp < edp) {
+		if (efidp_size(dp) == 0)
+			break;
 		efidp_format_device_path(buf, sizeof(buf), dp,
 		    (intptr_t)(void *)edp - (intptr_t)(void *)dp);
 		printf("%*s%s\n", indent, "", buf);