Bug 178923 - Locally copying several files to non-directory "works".
Locally copying several files to non-directory "works".
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: openssh (Show other bugs)
4.0
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:
Environment:
Last Closed: 2006-08-10 17:19:18 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
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

  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-1.1.3.2

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 $?
1
$ cat a b c
a
b
b

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.

/August.

Version-Release number of selected component (if applicable):
openssh-3.9p1-8.RHEL4.9

How reproducible:
Always

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

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

http://marc.theaimsgroup.com/?t=113776318200001&r=1&w=2
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... :)

/August.
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.

/August.

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.

http://rhn.redhat.com/errata/RHBA-2006-0303.html

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