Bug 1768 - scp: wrong error message when destination directory ends with a slash and is missing
Summary: scp: wrong error message when destination directory ends with a slash and is ...
Status: NEW
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: scp (show other bugs)
Version: -current
Hardware: All All
: P2 normal
Assignee: Assigned to nobody
URL: https://bugs.launchpad.net/bugs/18757
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-10 06:36 EST by Colin Watson
Modified: 2015-01-13 03:28 EST (History)
2 users (show)

See Also:


Attachments
set targetshouldbedirectory if there are two file arguments and argv[1] ends with a slash (307 bytes, patch)
2010-05-10 06:36 EST, Colin Watson
no flags Details | Diff
patch to improve error message (730 bytes, patch)
2015-01-09 03:21 EST, Jakub Jelen
no flags Details | Diff
patch to verify this problem in regress test suite (980 bytes, patch)
2015-01-09 03:22 EST, Jakub Jelen
no flags Details | Diff
Patch revised (726 bytes, patch)
2015-01-13 03:28 EST, Jakub Jelen
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Colin Watson 2010-05-10 06:36:19 EST
Created attachment 1846 [details]
set targetshouldbedirectory if there are two file arguments and argv[1] ends with a slash

Sami Haahtinen reported the following bug as https://bugs.launchpad.net/bugs/18757:

  It appears that scp gets confused if one tries to copy a file in to a missing directory:
  
  % pwd
  /tmp/test
  % touch foo
  % ls
  foo
  % scp foo localhost:/tmp/test/not-a-dir/
  user@localhost's password:
  scp: /tmp/test/not-a-dir/: Is a directory
  % scp foo localhost:/tmp/test/not-a-dir
  user@localhost's password:
  foo 100% 0 0.0KB/s 00:00
  % ls
  foo not-a-dir
  %
  
  above, the error in question should be "Directory does not exist" instead of "Is a directory"

This seems quite straightforward to fix without causing any compatibility problems: the scp client already passes -d to the server side if it knows that the target should be a directory because there are more than two file arguments, so it could test for a trailing slash in the same way.  Patch attached.
Comment 1 Mikel Mcdaniel 2014-12-03 05:48:46 EST
Hello.

This bug still exists today.

A friend of mine and I were confused and motivated enough to fix it ourselves and/or seek out this bug (or one of it's duplicates at https://bugs.launchpad.net/bugs/18757  or  https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=473137  or https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=152909  or https://bugzilla.redhat.com/show_bug.cgi?id=1142223).

I'm new to contributing to open source in general and I'm genuinely curious: How can I help get this resolved?  It seems like a bug, that negatively affects people, with a simple solution.
Comment 2 Jakub Jelen 2015-01-09 03:21:48 EST
Created attachment 2523 [details]
patch to improve error message

Hi,
I ran into this problem in RHBZ#1142223 [1] and tried to solve it. After some time of digging in the source code I came up with solution which I introduce here as a attachment. This added condition covers only this one problematic case and according to regression test cases published in portable tarbal, shouldn't bring here any regression.

Also I managed to write test case covering this problem. This file will be attached as the second file.

Also I would like to say that the previous patch doesn't work, because it will break recursive scp, for example:
> scp -r dir/ host:new_dir/
which is completely valid even if the new_dir doesn't exist.


[1] https://bugzilla.redhat.com/show_bug.cgi?id=1142223
Comment 3 Jakub Jelen 2015-01-09 03:22:36 EST
Created attachment 2524 [details]
patch to verify this problem in regress test suite
Comment 4 Jakub Jelen 2015-01-13 03:28:15 EST
Created attachment 2526 [details]
Patch revised