Bug 517 - bad "put" arg parsing
Summary: bad "put" arg parsing
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sftp (show other bugs)
Version: -current
Hardware: All Linux
: P2 normal
Assignee: OpenSSH Bugzilla mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-03-24 15:38 AEDT by Damien Miller
Modified: 2004-04-14 12:24 AEST (History)
0 users

See Also:


Attachments
Patch to fix problems fetching filenames with quotes in sftp (307 bytes, patch)
2003-03-25 12:46 AEDT, Jason McCormick
no flags Details | Diff
Test case showing results of patched sftp (569 bytes, text/plain)
2003-03-25 13:02 AEDT, Jason McCormick
no flags Details
More correct version (500 bytes, patch)
2003-03-25 14:51 AEDT, Ben Lindstrom
no flags Details | Diff
Patch to fix escapes of escapes (307 bytes, patch)
2003-03-26 13:50 AEDT, Jason McCormick
no flags Details | Diff
Patch to fix escaping of quotes (572 bytes, patch)
2003-03-26 13:54 AEDT, Jason McCormick
no flags Details | Diff
Parsing filenames surrounded in quotes. (838 bytes, patch)
2003-03-30 05:13 AEST, Jason McCormick
no flags Details | Diff
Patch for bux - minor fixes (841 bytes, patch)
2003-03-31 11:36 AEST, Jason McCormick
no flags Details | Diff
More concise patch (896 bytes, patch)
2003-05-15 18:50 AEST, Damien Miller
no flags Details | Diff
Concise & correct patch (1.97 KB, patch)
2003-05-16 01:01 AEST, Damien Miller
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Damien Miller 2003-03-24 15:38:57 AEDT
From bugs@openbsd.org:

From: Ward Wouts <ward@wizeazz.nl>
To: bugs@openbsd.org
Subject: problem with sftp
Date: Tue, 18 Mar 2003 10:26:03 +0100

Hello,

I'm seeing a problem with sftp where it's not possible to transfer files
with both 's and "s and spaces in the name. I think it's a problem with
the way get_pathname in sftp-int.c works, but my C is nowhere near good
enough to fix this. To reproduce try transfering a file named:

this"is' asillyname

with sftp.

Ward
Comment 1 Jason McCormick 2003-03-25 12:46:58 AEDT
Created attachment 257 [details]
Patch to fix problems fetching filenames with quotes in sftp
Comment 2 Jason McCormick 2003-03-25 12:55:30 AEDT
The above patch replaces strchr with strrchr so that the get_pathname will look
for the last ' or " for the filepath and not the first " or ' it comes to.

Test/Proof:

(Current SFTP)

sftp> dir
silly""file''2
this"is' asillyname
sftp> get "silly\"\"file\'\'2"
Couldn't stat remote file: No such file or directory
File "/home/jason/silly\" not found.
sftp> get "thCouldn't stat remote file: No such file or directory
File "/home/jason/this\" not found.
is\"is\' asillyname"


(Patched SFTP)

sftp> dir
silly""file''2
sftp> get "silly\"\"file\'\'2"
silly""file''2                                100%    3     0.4KB/s   00:00
Fetching /home/jason/this"is' asillyname to this"is' asillyname
sftp> exit

Only thing is that the filename seems to mess up the progress meter.  This
changed didn't seem to break any fetches and solves every " or ' problem I could
throw at it.
Comment 3 Jason McCormick 2003-03-25 13:02:56 AEDT
Created attachment 258 [details]
Test case showing results of patched sftp

This is the results of sftp operations before and after the sftp patch.  The
originals I put into the comment came out all funny.
Comment 4 Ben Lindstrom 2003-03-25 13:52:39 AEDT
As we are currently discussion on irc this fails to work for get "foo" "bar" 
case.  I think the strchr() is correct, just needs to be wrapped into a loop 
until you find (*end) != '\\'.

- Ben
Comment 5 Damien Miller 2003-03-25 14:02:43 AEDT
hm, maybe I should rewrite the line parser using lex/yacc
Comment 6 Jason McCormick 2003-03-25 14:46:15 AEDT
Or maybe I shouldn't make silly assumptions or have brain farts as to the syntax
of get and put.  Ben's got a better fix.
Comment 7 Ben Lindstrom 2003-03-25 14:51:23 AEDT
Created attachment 259 [details]
More correct version

I believe that this is more what we want.  I've only lightly tested it, but
it support get "foo\"bar"  "dog"  correctly.  The logic is just to loop through
and skip the char quot; if the character before it is a \.
Comment 8 Dan Astoorian 2003-03-26 05:04:57 AEDT
This fails to handle cases like "foo\\" where the quote is preceded by a
backslash but should not be escaped.
Comment 9 Jason McCormick 2003-03-26 13:50:26 AEDT
Created attachment 260 [details]
Patch to fix escapes of escapes

I think this *might* be the winner (?).  It seems to pass all the following
filename tests:

test test
test"\ "\
test"one
test\
test\"2
test\\\"""'
test\\\\

Can anyone come up with another test?
Comment 10 Jason McCormick 2003-03-26 13:54:54 AEDT
Created attachment 261 [details]
Patch to fix escaping of quotes

Ummm.. a little tired here and uploaded the wrong .patch file.	This is the
correct one that passes all of the following tests:

test test
test"\ "\
test"one
test\
test\"2
test\\\"""'
test\\\\
Comment 11 Jason McCormick 2003-03-28 11:28:01 AEDT
Comment on attachment 261 [details]
Patch to fix escaping of quotes

No valid in several cases.
Comment 12 Jason McCormick 2003-03-30 05:13:19 AEST
Created attachment 264 [details]
Parsing filenames surrounded in quotes.

Please test this patch.  Works for all above tests as well as doesn't break on
non-terminated quotes and filenames ending with a \.
Comment 13 Jason McCormick 2003-03-31 11:36:32 AEST
Created attachment 265 [details]
Patch for bux - minor fixes

Replaces check for " with quot for correct behavior.
Comment 14 Damien Miller 2003-05-15 18:50:43 AEST
Created attachment 299 [details]
More concise patch

Here is a more concise patch
Comment 15 Damien Miller 2003-05-16 01:01:27 AEST
Created attachment 302 [details]
Concise & correct patch

I just realised that we have never handled escape characters at all. This diff
adds escaping for quotes and the backslash character.
Comment 16 Damien Miller 2003-07-19 10:44:05 AEST
patch applied.
Comment 17 Damien Miller 2004-04-14 12:24:18 AEST
Mass change of RESOLVED bugs to CLOSED