scp -r bug

David Mitchell mitchell at ucar.edu
Tue Nov 14 06:54:14 EST 2000


I reported this bug back in 2.1.1p4, but never got any response.
Since it's still there in 2.3.0p1 I thought I would try again. If
you include a trailing slash on the source directory name, the
code in scp to extract the directory name fails. The result is
that rather than creating the directory on the far side, it
simply copies the files. In other words,
 
scp -r foo/ host:bar
acts like
scp -r foo/* host:bar
instead of 
scp -r foo host:bar  

The problem is due to this code in scp.c at about line 621:

     last = strrchr(name, '/');
       if (last == 0)
                last = name;
        else
                last++;

If you have a trailing slash, this code points last to the
terminating null character instead of the beginning of the
directory name. One possible solution is to remove the trailing
slash if it exists. Anything fancier might involve reworking the
whole directory parsing code. This is a simple fix which does the
trick. Adding this before the code above make scp act the way it
should.

       /* Bugfix. If the name has a trailing slash, take it off.
This
        * ensures that we actually get a directory name, not a
null string
        * if the user provides a trailing slash.
        */
      if (name[strlen(name) - 1] == '/') {
               name[strlen(name) - 1] = 0x00;
       };

It it possible to get this fix (or a similar one) merged back in?
I can apply all my local installations, but that's a hassle.
While this may seem like a minor bug, it can easily lead to the
inadvertant overwriting of the wrong file.

-David Mitchell





More information about the openssh-unix-dev mailing list