Bug 291132 - cp(1): copying recursively from / is broken since 82fc0d09e862
Summary: cp(1): copying recursively from / is broken since 82fc0d09e862
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 15.0-RELEASE
Hardware: Any Any
: --- Affects Many People
Assignee: Dag-Erling Smørgrav
URL: https://reviews.freebsd.org/D53863
Keywords:
Depends on:
Blocks: 15.0-metabug
  Show dependency tree / graph
 
Reported: 2025-11-21 13:35 UTC by Jan Noha
Modified: 2025-11-23 16:39 UTC (History)
2 users (show)

See Also:
des: mfc-stable15+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Noha 2025-11-21 13:35:01 UTC
Commit 82fc0d09e862 introduced an issue which you can reproduce by trying to copy contents of the root directory to somewhere else.

E.g.:

# mount -t tmpfs tmpfs /tmp
# cp -avx / /tmp
cp: /tmp//: Is a directory
Assertion failed: (strcmp(to.end + (*to.end == '/'), curr->fts_name) == 0), function copy, file /usr/src/bin/cp/cp.c, line 452.
Abort trap (core dumped)

It seems like a corner case, because I can work around it by doing
# cd /
# cp -avx ./ /tmp
Comment 1 Jan Noha 2025-11-21 13:41:40 UTC
(In reply to Jan Noha from comment #0)

Pasting the error again as it appears as of 07b7bd2311aff496b73f9552a5b3d8019685ef01

Assertion failed: (strcmp(to.end + (*to.end == '/'), curr->fts_name) == 0), function copy, file /usr/src/bin/cp/cp.c, line 527.

The previous one was when I built cp from 82fc0d09e862.
Comment 2 commit-hook freebsd_committer freebsd_triage 2025-11-22 12:12:49 UTC
A commit in branch main references this bug:

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

commit fe836c50120daed3e4084f43c27d8d650d36dee8
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2025-11-22 12:11:59 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2025-11-22 12:11:59 +0000

    cp: Fix copying the root directory

    When the source of the copy operation is the root directory, we should
    neither append it to the destination path on FTS_D nor trim it back off
    on FTS_DP.

    PR:             291132
    MFC after:      3 days
    Fixes:          82fc0d09e862 ("cp: Partly restore symlink folllowing.")
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D53863

 bin/cp/cp.c             |  7 ++++++-
 bin/cp/tests/cp_test.sh | 15 +++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
Comment 3 commit-hook freebsd_committer freebsd_triage 2025-11-22 18:43:55 UTC
A commit in branch stable/15 references this bug:

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

commit c4843e5805dec10ee552d21f19c8da7707c1fcbc
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2025-11-22 12:11:59 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2025-11-22 18:42:43 +0000

    cp: Fix copying the root directory

    When the source of the copy operation is the root directory, we should
    neither append it to the destination path on FTS_D nor trim it back off
    on FTS_DP.

    PR:             291132
    MFC after:      3 days
    Fixes:          82fc0d09e862 ("cp: Partly restore symlink folllowing.")
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D53863

    (cherry picked from commit fe836c50120daed3e4084f43c27d8d650d36dee8)

 bin/cp/cp.c             |  7 ++++++-
 bin/cp/tests/cp_test.sh | 15 +++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
Comment 4 commit-hook freebsd_committer freebsd_triage 2025-11-23 16:39:32 UTC
A commit in branch releng/15.0 references this bug:

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

commit 54808d50412aee31692f0041b4f78ddaf43bac8f
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2025-11-22 12:11:59 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2025-11-23 16:38:48 +0000

    cp: Fix copying the root directory

    When the source of the copy operation is the root directory, we should
    neither append it to the destination path on FTS_D nor trim it back off
    on FTS_DP.

    Approved by:    re (cperciva)
    PR:             291132
    MFC after:      3 days
    Fixes:          82fc0d09e862 ("cp: Partly restore symlink folllowing.")
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D53863

    (cherry picked from commit fe836c50120daed3e4084f43c27d8d650d36dee8)
    (cherry picked from commit c4843e5805dec10ee552d21f19c8da7707c1fcbc)

 bin/cp/cp.c             |  7 ++++++-
 bin/cp/tests/cp_test.sh | 15 +++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)