Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Apr 2026 06:06:34 +0000
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Cc:        Aaditya Singh <aadityavksingh@gmail.com>
Subject:   git: 50c1240ebfaf - main - mkimg: Fix parsing of filenames containing colons
Message-ID:  <69e07c6a.3d8c9.1f3f9d13@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch main has been updated by imp:

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

commit 50c1240ebfaf920ad12f05eb16d00f8b5b9d72e0
Author:     Aaditya Singh <aadityavksingh@gmail.com>
AuthorDate: 2026-02-21 18:13:54 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2026-04-16 06:05:21 +0000

    mkimg: Fix parsing of filenames containing colons
    
    When using PART_KIND_FILE (-p type:=filename), mkimg uses a colon
    to separate an optional offset (e.g., filename:offset).
    
    strsep() was being used to split the string at the first colon.
    This caused failures when the filename itself contained a colon
    (e.g., "th:is").
    
    This patch uses stat() to check if the entire string exists as a
    file. If so, use it directly without splitting.
    
    If the full string is not a valid file, fall back to splitting
    at the right-most colon using strrchr().
    
    Uses errc() to fail and exit immediately when an existing directory
    is input instead of a file in PART_KIND_FILE mode.
    
    PR: 257960
    Signed-off-by: Aaditya Singh <aadityavksingh@gmail.com>
    Reviewed by: jlduran
    Pull Request: https://github.com/freebsd/freebsd-src/pull/2041
---
 usr.bin/mkimg/mkimg.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/usr.bin/mkimg/mkimg.c b/usr.bin/mkimg/mkimg.c
index c625b49dc29a..4a288d66be81 100644
--- a/usr.bin/mkimg/mkimg.c
+++ b/usr.bin/mkimg/mkimg.c
@@ -446,6 +446,8 @@ mkimg(void)
 {
 	FILE *fp;
 	struct part *part;
+	struct stat sb;
+	char *p;
 	lba_t block, blkoffset;
 	uint64_t bytesize, byteoffset;
 	char *size, *offset;
@@ -468,12 +470,28 @@ mkimg(void)
 		/* Look for an offset. Set size too if we can. */
 		switch (part->kind) {
 		case PART_KIND_SIZE:
-		case PART_KIND_FILE:
 			offset = part->contents;
 			size = strsep(&offset, ":");
-			if (part->kind == PART_KIND_SIZE &&
-			    expand_number(size, &bytesize) == -1)
+			if (expand_number(size, &bytesize) == -1)
 				error = errno;
+			break;
+		case PART_KIND_FILE:
+			size = part->contents;
+			if (stat(part->contents, &sb) == 0) {
+				if (S_ISDIR(sb.st_mode)) {
+					errc(EX_IOERR, EISDIR, "partition %d",
+					    part->index + 1);
+				}
+				offset = NULL;
+			} else {
+				p = strrchr(part->contents, ':');
+				if (p != NULL) {
+					*p = '\0';
+					offset = p + 1;
+				} else {
+					offset = NULL;
+				}
+			}
 			if (offset != NULL) {
 				if (*offset != '+')
 					abs_offset = true;


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69e07c6a.3d8c9.1f3f9d13>