]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Avoid misbehavior of a cross-device "mv" or "install".
authorJim Meyering <meyering@redhat.com>
Thu, 15 Nov 2007 12:04:13 +0000 (13:04 +0100)
committerJim Meyering <meyering@redhat.com>
Thu, 15 Nov 2007 12:04:13 +0000 (13:04 +0100)
Those programs must not dereference a destination symlink.
* src/copy.c (copy_reg): Don't treat a dangling destination symlink
differently in move mode.  In move mode, the only way the added
O_EXCL can cause failure is when some other process has recreated
the file this code unlinked a few instructions before.

ChangeLog
src/copy.c

index 308a4a53c4f9bb6bd585086fa296bb70d194f320..4ba238955bb59674bcabee210c9d459e64703055 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2007-11-15  Jim Meyering  <meyering@redhat.com>
+
+       Avoid misbehavior of a cross-device "mv" or "install".
+       Those programs must not dereference a destination symlink.
+       * src/copy.c (copy_reg): Don't treat a dangling destination symlink
+       differently in move mode.  In move mode, the only way the added
+       O_EXCL can cause failure is when some other process has recreated
+       the file this code unlinked a few instructions before.
+
 2007-11-14  Jim Meyering  <meyering@redhat.com>
 
        Another bootstrap kludge.
index e1cd5fa21cf41acd6fe38a915cb3a4cbb454c23b..1a265e3c2439e19bfa57c897279470ddef9759cb 100644 (file)
@@ -371,8 +371,9 @@ copy_reg (char const *src_name, char const *dst_name,
         the above open fails with EEXIST.  If that happens, and
         lstat'ing the DST_NAME shows that it is a symlink, repeat
         the open call, but this time with the name of the final,
-        missing directory entry.  */
-      if (dest_desc < 0 && dest_errno == EEXIST)
+        missing directory entry.  All of this is relevant only for
+        cp, i.e., not in move_mode. */
+      if (dest_desc < 0 && dest_errno == EEXIST && ! x->move_mode)
        {
          struct stat dangling_link_sb;
          if (lstat (dst_name, &dangling_link_sb) == 0