Bug 1297464

Summary: mv data loss when destination directory appears in source list more than once
Product: [Fedora] Fedora Reporter: Yeasah Pell <yeasah>
Component: coreutilsAssignee: Ondrej Vasik <ovasik>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 23CC: admiller, kdudka, kzak, ooprala, ovasik, p, twaugh
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: coreutils-8.24-5.fc23 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-01-15 23:24:06 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
proposed upstream fix none

Description Yeasah Pell 2016-01-11 15:21:44 UTC
Description of problem:
When mv is mistakenly given arguments including a directory listed at least twice as a source as well as the destination, it will destroy that directory and everything in it will be lost.

Version-Release number of selected component (if applicable):
coreutils-8.24-4.fc23.x86_64

How reproducible:
Trivially reproducible with steps

Steps to Reproduce:
1. mkdir test
2. mv test test test

Actual results:
mv: cannot move 'test' to a subdirectory of itself, 'test/test'
mv: warning: source directory 'test' specified more than once
(and the directory and all contents are destroyed)

Expected results: (per EPEL7)
mv: cannot move 'test' to a subdirectory of itself, 'test/test'
mv: will not create hard link 'test/test' to directory 'test/test'
(and the directory remains unchanged with contents intact)


Additional info:

Comment 1 Pádraig Brady 2016-01-11 18:15:23 UTC
Ouch, this looks like due to the 'return true' at:
http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=v8.23-31-g90aa291

I'll fix this upstream this evening.

Comment 2 Pádraig Brady 2016-01-11 18:37:59 UTC
This avoids the issue at least.
Full patch coming up...

@@ -2281,7 +2283,8 @@ copy_internal (char const *src_name, char const *dst_name,
               /* We only do backups in move mode and for non dirs,
                  and in move mode this won't be the issue as the source will
                  be missing for subsequent attempts.
-                 There we just warn and return here.  */
+                 Therefore we just warn and return here.  */
+              *copy_into_self = true;
               return true;
             }
           else if (x->dereference == DEREF_ALWAYS

Comment 3 Pádraig Brady 2016-01-12 12:55:06 UTC
Created attachment 1113926 [details]
proposed upstream fix

Comment 4 Ondrej Vasik 2016-01-12 23:12:20 UTC
Thanks for the patch and quick fix - there is a typo in the NEWS entry (no londer). Other than that, looks fine, I'll apply this to rawhide and f23...well - later today ;).

Comment 5 Fedora Update System 2016-01-13 12:36:51 UTC
coreutils-8.24-5.fc23 has been submitted as an update to Fedora 23. https://bodhi.fedoraproject.org/updates/FEDORA-2016-477caff2e3

Comment 6 Fedora Update System 2016-01-14 11:25:42 UTC
coreutils-8.24-5.fc23 has been pushed to the Fedora 23 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2016-477caff2e3

Comment 7 Fedora Update System 2016-01-15 23:24:01 UTC
coreutils-8.24-5.fc23 has been pushed to the Fedora 23 stable repository. If problems still persist, please make note of it in this bug report.