Bugs item #1960894, was opened at 2008-05-09 09:50
Message generated for change (Comment added) made by heiner0
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=703942&aid=1960894&group_id=125852

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Heiner (heiner0)
Assigned to: Nobody/Anonymous (nobody)
Summary: libssh2_scp_* do not handle whitespace in file names

Initial Comment:
it seems that some libssh2 SCP functions do not correctly handle
whitespace in file names. When trying to copy a file named "with blanks"
using libssh2_scp_recv() I get an error message.

The reason is that libssh2 builds a "scp" command line that will be
run on the remote side, but does not take care to quote the file
name. It runs the equivalent of the following "ssh" command:

    scp -f with blanks

instead of (note the quotation marks):

    scp -f 'with blanks'

The code causing problems is in libssh2_scp_recv():

    memcpy(session->scpRecv_command, "scp -f ", sizeof("scp -f ") - 1);
    memcpy(session->scpRecv_command + sizeof("scp -f ") - 1, path,
           path_len);

    (Similar code is in libssh2_scp_send()).

Variable "path" should get correct quoting.

I attached the function shell_quotearg() that could be used for quoting
the path name.


----------------------------------------------------------------------

>Comment By: Heiner (heiner0)
Date: 2008-11-07 08:53

Message:
[This comment is the same as request 2233372]



The attached patch fixes

[1960894] libssh2_scp_* do not handle whitespace in file names

It introduces a new (private) function
libssh2_shell_quotearg()

for "quoting" a shell command argument (e.g. a file name). Example:
one two

gets converted to
'one two'

(note the single quotation marks).

The quoting style ensures that the results work with both Bourne Shell
derivates (sh, ksh, ksh93, bash, zsh) and C-Shell dialects (csh, tcsh).

The new (private) macro
libssh2_shell_quotedsize()

calculates the maximum size a quoted string can have; this is useful for
allocating a memory buffer for the results.

I've tested the code with
Linux: bash, ksh93, tcsh
Solaris: sh, bash, csh

File Added: shellquote.patch

----------------------------------------------------------------------

Comment By: Daniel Stenberg (bagder)
Date: 2008-09-29 13:47

Message:
So can you please submit a complete patch that makes use of the code you
suggest? 

----------------------------------------------------------------------

Comment By: Heiner (heiner0)
Date: 2008-08-21 16:58

Message:
Logged In: YES 
user_id=1568315
Originator: YES

The shell_quotearg() function had problems when the login shell of the
remote
user was the C-Shell (csh). The new function works with CSH as well.
It includes a small test program: cc -DMAIN -o qtest shell_quotearg.c;
./qtest "someone's test"

File Added: shell_quotearg.c

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=703942&aid=1960894&group_id=125852

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
libssh2-devel mailing list
libssh2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libssh2-devel

Reply via email to