Bug 178923 - Locally copying several files to non-directory "works".
Locally copying several files to non-directory "works".
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: openssh (Show other bugs)
i386 Linux
medium Severity high
: ---
: ---
Assigned To: Tomas Mraz
Brian Brock
Depends On:
Blocks: 181409
  Show dependency treegraph
Reported: 2006-01-25 10:18 EST by Björn Augustsson
Modified: 2007-11-30 17:07 EST (History)
0 users

See Also:
Fixed In Version: RHBA-2006-0303
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2006-08-10 17:19:18 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
Patch against 4.2p1 (1.13 KB, patch)
2006-01-25 10:28 EST, Björn Augustsson
no flags Details | Diff

External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2006:0303 normal SHIPPED_LIVE openssh bug fix update 2006-08-09 00:00:00 EDT

  None (edit)
Description Björn Augustsson 2006-01-25 10:18:29 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-

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):

How reproducible:

Steps to Reproduce:
1. See example above in the "Description" field.

Actual Results:  Data loss.

Expected Results:  An error message, and no lost data.

Additional info:

I mailed this to the openssh-unix-dev mailing list, archived at

Comment 1 Björn Augustsson 2006-01-25 10:28:32 EST
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... :)

Comment 2 Björn Augustsson 2006-02-01 12:00:37 EST
This is from source-changes@cvs.openbsd.org, apparently the fix
is in upstream.


Date: Tue, 31 Jan 2006 03:35:43 -0700 (MST)
Subject: CVS: cvs.openbsd.org: src

CVSROOT:        /cvs
Module name:    src
Changes by:     djm@cvs.openbsd.org     2006/01/31 03:35:43

Modified files:
        usr.bin/ssh    : scp.c

Log message:
"scp a b c" shouldn't clobber "c" when it is not a directory, report and
fix from biorn@; ok markus@
Comment 3 Bob Johnson 2006-04-11 13:16:18 EDT
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.
Comment 7 Red Hat Bugzilla 2006-08-10 17:19:21 EDT
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.


Note You need to log in before you can comment on or make changes to this bug.