git: bfa36136a56c - main - kboot: Fix file2str() buffer under-read

From: Warner Losh <imp_at_FreeBSD.org>
Date: Tue, 01 Sep 2026 13:54:51 UTC
The branch main has been updated by imp:

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

commit bfa36136a56cdcec73ee5771c4c0a117469ff020
Author:     Aryan Arora <aryanarora.w1@gmail.com>
AuthorDate: 2026-08-07 13:37:17 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2026-09-01 13:54:12 +0000

    kboot: Fix file2str() buffer under-read
    
    Signed-off-by: Aryan Arora <aryanarora.w1@gmail.com>
    Reviewed by: imp
    Pull Request: https://github.com/freebsd/freebsd-src/pull/2359
---
 stand/kboot/libkboot/util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/stand/kboot/libkboot/util.c b/stand/kboot/libkboot/util.c
index c7fe8b542643..f1902710612a 100644
--- a/stand/kboot/libkboot/util.c
+++ b/stand/kboot/libkboot/util.c
@@ -26,7 +26,7 @@ file2str(const char *fn, char *buffer, size_t buflen)
 	/*
 	 * Trim trailing white space
 	 */
-	while (isspace(buffer[len - 1]))
+	while (len > 0 && isspace(buffer[len - 1]))
 		buffer[--len] = '\0';
 	host_close(fd);
 	return true;