Bug 257960 - mkimg: partition 1: No such file or directory when using a ":" in the file name
Summary: mkimg: partition 1: No such file or directory when using a ":" in the file name
Status: In Progress
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 13.0-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: Warner Losh
URL:
Keywords: regression, vendor
Depends on:
Blocks:
 
Reported: 2021-08-20 07:06 UTC by devnull
Modified: 2026-10-28 05:53 UTC (History)
5 users (show)

See Also:
linimon: mfc-stable15?
linimon: mfc-stable14?


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description devnull freebsd_committer freebsd_triage 2021-08-20 07:06:13 UTC
Hi,

This was working on 12.1 at least, but due to new syntax additions this broke file name read.


Cheers,
Franco
Comment 1 Ed Maste freebsd_committer freebsd_triage 2021-08-20 22:47:47 UTC
Can you add an example failing command line
Comment 2 devnull freebsd_committer freebsd_triage 2021-08-21 06:17:54 UTC
Sorry, was in a hurry yesterday:

# touch th:is
# mkimg -s gpt -o out:ok -p freebsd-ufs:=th:is
mkimg: partition 1: No such file or directory

There's two possible workarounds at the moment: use relative paths if the directory contains a colon or use a symbolic link if the file name contains it.

If you do

# touch th

and run the prior command you can see that it does find the file now and fails with

mkimg: writing metadata: Device not configured

as expected.


Cheers,
Franco
Comment 3 Ed Maste freebsd_committer freebsd_triage 2024-09-05 16:54:50 UTC
manu it looks like this comes from 8f3c71c85e5f
Comment 4 Aaditya Singh 2026-02-22 07:07:52 UTC
I have made a Github PR to try fixing this bug
[https://github.com/freebsd/freebsd-src/pull/2041]

It 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().
Comment 5 commit-hook freebsd_committer freebsd_triage 2026-04-16 06:07:02 UTC
A commit in branch main references this bug:

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(-)
Comment 6 Aaditya Singh 2026-05-04 20:34:49 UTC
The status of this bug ought to be changed now
Comment 7 commit-hook freebsd_committer freebsd_triage 2026-10-28 05:53:29 UTC
A commit in branch stable/15 references this bug:

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

commit 8aaf8771e2543690d60aa0d008f250d151f450cb
Author:     Aaditya Singh <aadityavksingh@gmail.com>
AuthorDate: 2026-02-21 18:13:54 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2026-10-28 01:11:42 +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
    (cherry picked from commit 50c1240ebfaf920ad12f05eb16d00f8b5b9d72e0)

 usr.bin/mkimg/mkimg.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)