GNU bug report logs - #70558
ln -sfr stats the wrong file

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: coreutils; Reported by: David Leonard <d+gnubugs@HIDDEN>; merged with #70561; dated Thu, 25 Apr 2024 05:34:08 UTC; Maintainer for coreutils is bug-coreutils@HIDDEN.
Merged 70558 70561. Request was from Collin Funk <collin.funk1@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 25 Apr 2024 05:33:10 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Apr 25 01:33:09 2024
Received: from localhost ([127.0.0.1]:60358 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1rzrjH-00064J-K0
	for submit <at> debbugs.gnu.org; Thu, 25 Apr 2024 01:33:09 -0400
Received: from lists.gnu.org ([2001:470:142::17]:46474)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <d+gnubugs@HIDDEN>)
 id 1rzgJ0-0004vo-Uw
 for submit <at> debbugs.gnu.org; Wed, 24 Apr 2024 13:21:18 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <d+gnubugs@HIDDEN>)
 id 1rzgIe-000379-4j
 for bug-coreutils@HIDDEN; Wed, 24 Apr 2024 13:20:52 -0400
Received: from arx.adaptive-enterprises.com ([58.96.48.22]
 helo=adaptive-enterprises.com)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256)
 (Exim 4.90_1) (envelope-from <d+gnubugs@HIDDEN>)
 id 1rzgIb-0007cI-B3
 for bug-coreutils@HIDDEN; Wed, 24 Apr 2024 13:20:51 -0400
Received: by adaptive-enterprises.com (OpenSMTPD) with ESMTP id f283ee76
 for <bug-coreutils@HIDDEN>; Thu, 25 Apr 2024 03:20:30 +1000 (AEST)
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=adaptive-enterprises.com;
 h=date:from:to:subject:message-id:mime-version:content-type; s=
 arx; bh=4ox0I10gpzFHiPLZhyjOXfUtI04=; b=HUTmwiZmm2/HFxZqw0HMx/mE
 YvD4MkooXCfdD2fH+7aUkuADW3sUiIiCd7MIDpEYBi+43bqaAlWdXPFE88k//tuR
 zdE+lj4sOwAhlR5yRyhEl6qA5vzHD8SkCiFv7Kphw41Ma1pt9XI7Z02pQI+PPjjU
 2Gi2jcf8J0ymIL3+49U=
DomainKey-Signature: a=rsa-sha1; c=nofws; d=adaptive-enterprises.com; h=
 date:from:to:subject:message-id:mime-version:content-type; q=
 dns; s=arx; b=jVLQDS8Fu+6oq/7CoUaCZOBrNO6GOoT8Et1quY4sywnQaU+2U+
 1c7rzUJfizxT4UU7Rn2cEtgEZeD54ajKW9GCDLUTn1t7LvHjlkzvtIfs1o4mvwt9
 6c3Xl3M/SHsgWKKecaGnmiGaXhwzyI6zQxW1HfcJdSPBcfpJJvJ2cYV5U=
Received: from cwm (<unknown> [10.1.1.12])
 by arx.adaptive-enterprises.com (OpenSMTPD) with ESMTPSA id e613281d
 (TLSv1.3:TLS_CHACHA20_POLY1305_SHA256:256:NO) auth=yes user=d
 for <bug-coreutils@HIDDEN>; Thu, 25 Apr 2024 03:20:29 +1000 (AEST)
Date: Thu, 25 Apr 2024 03:20:27 +1000 (AEST)
From: David Leonard <d+gnubugs@HIDDEN>
To: bug-coreutils@HIDDEN
Subject: ln -sfr stats the wrong file
Message-ID: <8071o212-8682-97o5-nnp8-65op218p0s89@HIDDEN>
User-Agent: Alpine 2.26 (DEB 649 2022-06-02)
MIME-Version: 1.0
Content-Type: text/plain; format=flowed; charset=US-ASCII
Received-SPF: pass client-ip=58.96.48.22;
 envelope-from=d+gnubugs@HIDDEN;
 helo=adaptive-enterprises.com
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 0.9 (/)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Thu, 25 Apr 2024 01:33:05 -0400
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.1 (/)


When analyzing file accesses with strace, I noticed that ln stats an
unrelated file. This only happens with the opions -sfr and when the dest
symlink already exists.

Here's a reproduction script:

     # setup
     mkdir -p a b
     > b/x
     ln -fs anything a/x

     # ln -sfr b/x a/x
     strace -o trace.out --decode-fds=path -e %file \
 	src/ln -sfr b/x a/x

     test $(readlink a/x) = ../b/x
     grep stat trace.out

The invalid stat that happens is:

     newfstatat(AT_FDCWD</tmp/lnbug>, "../b/x", 0x7ffdb94a0270, 0) = -1 ENOENT (No such file or directory)

The cause seems to be in src/ln.c's do_link() where the `source` "b/x" is
converted to "../b/x" by

         if (relative)
               source = rel_source = convert_abs_rel (source, dest);

and then the test to see if deleting the destination file would delete
the source works by checking hard links on the source.

 	if (source_status != 0)
 	    source_status = stat (source, &source_stats);

Except that -r made source relative to the dest directory.




Acknowledgement sent to David Leonard <d+gnubugs@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-coreutils@HIDDEN. Full text available.
Report forwarded to bug-coreutils@HIDDEN:
bug#70558; Package coreutils. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Fri, 17 Oct 2025 19:15:01 UTC

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