Red Hat Bugzilla – Bug 178923
Locally copying several files to non-directory "works".
Last modified: 2007-11-30 17:07:22 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050921 Red Hat/1.7.12-184.108.40.206
Description of problem:
When copying several files, the last one must be a directory, but if the last one is a file, scp will overwrite it. This example explains it well.
Here's something to try:
$ echo a >a
$ echo b >b
$ echo c >c
$ scp a b c
$ echo $?
$ cat a b c
Ouch! Also, for comparison:
$ cp a b c
cp: copying multiple files, but last argument `c' is not a directory
Try `cp --help' for more information.
$ rcp a b c
rcp: c: Not a directory.
Note that the cp behavior is specified in SuSv2.
(http://www.opengroup.org/onlinepubs/007908799/xcu/cp.html, "Second synopsis")
Also, and this might be a separate bug, note how openssh exits with
return code of 1.
Note: This also happens to the current version of openssh in RHEL 3 (openssh-3.6.1p2-33.30.6)
I have a patch for your review as well, I'll attach it.
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. See example above in the "Description" field.
Actual Results: Data loss.
Expected Results: An error message, and no lost data.
I mailed this to the openssh-unix-dev mailing list, archived at
Created attachment 123674 [details]
Patch against 4.2p1
Here's a patch that seems to fix it. Against 4.2p1 (but it's not exactly a
super advanced patch, so it should be readily portable.)
The first chunk fixed the eating of the innocent file, and is fairly
obvoiusly correct. The second one fixes the fact that there's no error
message. I'm less certain of that one not breaking anything else.
(A colleague wrote that one... :)
This is from email@example.com, apparently the fix
is in upstream.
Date: Tue, 31 Jan 2006 03:35:43 -0700 (MST)
Subject: CVS: cvs.openbsd.org: src
Module name: src
Changes by: firstname.lastname@example.org 2006/01/31 03:35:43
usr.bin/ssh : scp.c
"scp a b c" shouldn't clobber "c" when it is not a directory, report and
fix from biorn@; ok markus@
This issue is on Red Hat Engineering's list of planned work items
for the upcoming Red Hat Enterprise Linux 4.4 release. Engineering
resources have been assigned and barring unforeseen circumstances, Red
Hat intends to include this item in the 4.4 release.
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on the solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.