GNU bug report logs - #76702
coreutils 9.1 cp --parents --preserve /dir/file fstat relative dir

Previous Next

Package: coreutils;

Reported by: "Alan J. Goalby" <alan.j.goalby <at> gmail.com>

Date: Mon, 3 Mar 2025 04:33:01 UTC

Severity: normal

To reply to this bug, email your comments to 76702 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#76702; Package coreutils. (Mon, 03 Mar 2025 04:33:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Alan J. Goalby" <alan.j.goalby <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Mon, 03 Mar 2025 04:33:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Alan J. Goalby" <alan.j.goalby <at> gmail.com>
To: bug-coreutils <at> gnu.org
Subject: coreutils 9.1 cp --parents --preserve /dir/file fstat relative dir
Date: Sun, 2 Mar 2025 15:18:17 +0000
[Message part 1 (text/plain, inline)]
When "cp --parents --preserve /dir/file /target/" needs to create
/target/dir/, it appears to try to Fstat information from relative
path "dir", not the actual parent path "/dir".

E.g., "cd /tmp && mkdir NewDir && cp -a --parents /etc/passwd NewDir"
will fail, as (1) below - unless (2) /tmp/etc exists, or (3) use "cd
/", or (4) omit "--preserve".

My enclosed cp-par-pres-demo.sh shows that:

(1) Cp  --parents --preserve /dir/file /target/" will

 * log ENOENT for relative "dir" for a missing /target/dir;

 * create that missing parent /target/dir with mode 700;

 * create a missing non-parent output correctly; and

 * return error status 1.

(2) If ./dir exists, Cp takes /target/dir mode from it, not /dir.

(3) With "cd /", this works normally, since "dir" is /dir.

(4) Without --preserve, there is no error.

This happens for Debian 12.9 coreutils 9.1-1, under linux 6.1.115
amd64, on an ext4 partition, for root and other users, e.g. nobody.
And for an ext3 copy Chroot under linux 5.10.226.

(md5sum --check verifies coreutils.md5sums lib*.msd5sums et al.)

This does not happen for Debian 11.11 coreutils 8.32-4+b1, under linux
5.10.226 amd64 on ext4, nor for earlier versions on i386 ext3.

I enclose logs from those good Debian 11 and wrong Debian 12 runs.

My other tests show this not happening for relative input paths.

Hope this helps.

Alan J. Goalby
[cp-par-pres-demo.sh (application/x-sh, attachment)]
[fail-deb12p9-demo.log (text/plain, attachment)]
[good-deb11p11-demo.log (text/plain, attachment)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#76702; Package coreutils. (Mon, 03 Mar 2025 13:22:02 GMT) Full text and rfc822 format available.

Message #8 received at 76702 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: "Alan J. Goalby" <alan.j.goalby <at> gmail.com>, 76702 <at> debbugs.gnu.org
Subject: Re: bug#76702: coreutils 9.1 cp --parents --preserve /dir/file fstat
 relative dir
Date: Mon, 3 Mar 2025 13:21:02 +0000
On 02/03/2025 15:18, Alan J. Goalby wrote:
> When "cp --parents --preserve /dir/file /target/" needs to create
> /target/dir/, it appears to try to Fstat information from relative
> path "dir", not the actual parent path "/dir".
> 
> E.g., "cd /tmp && mkdir NewDir && cp -a --parents /etc/passwd NewDir"
> will fail, as (1) below - unless (2) /tmp/etc exists, or (3) use "cd
> /", or (4) omit "--preserve".
> 
> My enclosed cp-par-pres-demo.sh shows that:
> 
> (1) Cp  --parents --preserve /dir/file /target/" will
> 
>   * log ENOENT for relative "dir" for a missing /target/dir;
> 
>   * create that missing parent /target/dir with mode 700;
> 
>   * create a missing non-parent output correctly; and
> 
>   * return error status 1.
> 
> (2) If ./dir exists, Cp takes /target/dir mode from it, not /dir.
> 
> (3) With "cd /", this works normally, since "dir" is /dir.
> 
> (4) Without --preserve, there is no error.
> 
> This happens for Debian 12.9 coreutils 9.1-1, under linux 6.1.115
> amd64, on an ext4 partition, for root and other users, e.g. nobody.
> And for an ext3 copy Chroot under linux 5.10.226.
> 
> (md5sum --check verifies coreutils.md5sums lib*.msd5sums et al.)
> 
> This does not happen for Debian 11.11 coreutils 8.32-4+b1, under linux
> 5.10.226 amd64 on ext4, nor for earlier versions on i386 ext3.
> 
> I enclose logs from those good Debian 11 and wrong Debian 12 runs.
> 
> My other tests show this not happening for relative input paths.

This should be fixed with:
https://github.com/coreutils/coreutils/commit/c6b1fe434

It would be good to get that applied to Debian 12.

thanks,
Pádraig




This bug report was last modified today.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.