git: 1b92999e67b6 - stable/13 - efibootmgr: fix potential endless loop with -v

From: Andriy Gapon <avg_at_FreeBSD.org>
Date: Sat, 17 Feb 2024 19:22:41 UTC
The branch stable/13 has been updated by avg:

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

commit 1b92999e67b6cbfa75a9def2a33464080ba33a05
Author:     Andriy Gapon <avg@FreeBSD.org>
AuthorDate: 2022-10-25 21:10:39 +0000
Commit:     Andriy Gapon <avg@FreeBSD.org>
CommitDate: 2024-02-17 19:22:08 +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.
    
    (cherry picked from commit bf87d4a4bfaa86e97079754e93fe14595adf07c5)
---
 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 8dcf9876486d..be1157b4aa84 100644
--- a/usr.sbin/efibootmgr/efibootmgr.c
+++ b/usr.sbin/efibootmgr/efibootmgr.c
@@ -784,6 +784,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);