From nobody Sat Nov 22 18:42:55 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4dDLYq52SFz6HblP for ; Sat, 22 Nov 2025 18:42:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dDLYq46wKz3nsF for ; Sat, 22 Nov 2025 18:42:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763836975; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PVMHG59SqCKjW8e5GQa7AeqFaRAWi9f4gDuCIveV/dE=; b=pWWoIaVJHYzeJhaY/fa7GmZgqgzXItCvcwfaW2PYoCOefgzr29zksoLxclOhDGTl3DGTq9 6dS4mnLRU7Hh3pDM7EwJ5UYrZgzvcw4nBZxCNq28s8C0lSYpPrKraGTJqgEVt5ee29vjfC EZCG9a8PtBqQZ8/GAOpoULdMM51aGqPHibx0yBVmHlDlCmFEwWYEFz4iaU01TJLloRKThL dxe9Dq3/rrlFS2f0Gv29autkjQa8p4B5hgoRXAEziU9UG3PqeEWn5VGI6Yfemm5pxS93Ci E9ssCpHnQvUhx2S6mh+RUALRCEUA5fu2UE0Ml6C8HM1Z2EIurzx0VNYhlVL8iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1763836975; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PVMHG59SqCKjW8e5GQa7AeqFaRAWi9f4gDuCIveV/dE=; b=eg0Qd3vFC2/BQAmmknXLHZgfgsqqgGjY365rZW5xsTzmvpF8tTzcvMwU33jE/4uO0htqBB m/bxU6aUOWLOiz5J7iE58deIsSvvhtC5HOu5+4b+qAXYVsc9aDtGBjfgiv2gG1Ggu1IgFh 4lqd7QywnDKv5K3X2oU5sfXnYzOyHgQwcMA+JH9bIRFsGAdslAOzDMBaAEsiP93/SNh4SA VmJQYX23pb3eZGOOnRoTkAg/d4BbuuWiAH2+KcERBhbqYBokB6a1XTkBoXmJ80bxw5e+xC hxmVR+Fq8rsF0HqMgbKnUr2sJYht7wbYhzpTnGcAqtuzlirHx5GPM0pO8/D6Lw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1763836975; a=rsa-sha256; cv=none; b=wgbDiyOCV2F6ViFxvHJOJu1kFsAFza8TIELHKcwSV28oV2XIRZPWCPDZdpihJMKnAm+tQF 8Hcnr/fBHBOLecgBO8HwNNNWhiyHkWs042OjWXvMtLA7KM8PRHaWTXjSiUWA9i+NoMXOm/ qOjETOBehuxIqrBbK7sTL0mpiPlQhklbD0xN4m6wfggIs2IgCpfi0jlrBQKYvB1nC+NAvQ rzqCOP8hDRX7s3BMwBQ/3CCJZJKIoLUKMKYPQq5zcUY5xAgR7rO/6qF0XtC3FEdTroMGlo Z//uhQ9kW7GcPkSGCUr5aQv/yNPqY5mImgqRuUlOFh7I2F15YoCn3+4iSo52Fg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dDLYq3ZbCz18t8 for ; Sat, 22 Nov 2025 18:42:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 219e5 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 22 Nov 2025 18:42:55 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav Subject: git: c4843e5805de - stable/15 - cp: Fix copying the root directory List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: c4843e5805dec10ee552d21f19c8da7707c1fcbc Auto-Submitted: auto-generated Date: Sat, 22 Nov 2025 18:42:55 +0000 Message-Id: <6922042f.219e5.6a6171d1@gitrepo.freebsd.org> The branch stable/15 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=c4843e5805dec10ee552d21f19c8da7707c1fcbc commit c4843e5805dec10ee552d21f19c8da7707c1fcbc Author: Dag-Erling Smørgrav AuthorDate: 2025-11-22 12:11:59 +0000 Commit: Dag-Erling Smørgrav 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(-) diff --git a/bin/cp/cp.c b/bin/cp/cp.c index 38fe65399d06..7ac1e5f6a4c4 100644 --- a/bin/cp/cp.c +++ b/bin/cp/cp.c @@ -433,6 +433,8 @@ copy(char *argv[], enum op type, int fts_options, struct stat *root_stat) sep = strchr(to.base, '\0'); sep[0] = '/'; sep[1] = '\0'; + } else if (strcmp(curr->fts_name, "/") == 0) { + /* special case when source is the root directory */ } else { /* entering a directory; append its name to to.path */ len = snprintf(to.end, END(to.path) - to.end, "%s%s", @@ -520,6 +522,8 @@ copy(char *argv[], enum op type, int fts_options, struct stat *root_stat) if (type == DIR_TO_DNE && curr->fts_level == FTS_ROOTLEVEL) { /* this is actually our created root */ + } else if (strcmp(curr->fts_name, "/") == 0) { + /* special case when source is the root directory */ } else { while (to.end > to.path && *to.end != '/') to.end--; @@ -551,7 +555,8 @@ copy(char *argv[], enum op type, int fts_options, struct stat *root_stat) /* Not an error but need to remember it happened. */ if (to.path[0] == '\0') { /* - * This can happen in two cases: + * This can happen in three cases: + * - The source path is the root directory. * - DIR_TO_DNE; we created the directory and * populated root_stat earlier. * - FILE_TO_DIR if a source has a trailing slash; diff --git a/bin/cp/tests/cp_test.sh b/bin/cp/tests/cp_test.sh index b637f862b7d3..af309ca7ea80 100755 --- a/bin/cp/tests/cp_test.sh +++ b/bin/cp/tests/cp_test.sh @@ -747,9 +747,23 @@ dstmode_body() atf_check cmp dir/file dst/file } +atf_test_case root +root_head() +{ + atf_set "descr" "Test copying the root directory" +} +root_body() +{ + atf_check mkdir dst + atf_check -s exit:1 \ + -e inline:"cp: / is a directory (not copied).\n" \ + cp / dst +} + atf_test_case to_root cleanup to_root_head() { + atf_set "descr" "Test copying to the root directory" atf_set "require.user" "unprivileged" } to_root_body() @@ -893,6 +907,7 @@ atf_init_test_cases() atf_add_test_case to_deaddirlink atf_add_test_case to_link_outside atf_add_test_case dstmode + atf_add_test_case root atf_add_test_case to_root atf_add_test_case dirloop atf_add_test_case unrdir