Bug 778 - sftp client globs entire path, directories enclosed in square brackets are unusable
Summary: sftp client globs entire path, directories enclosed in square brackets are un...
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sftp (show other bugs)
Version: -current
Hardware: ix86 Linux
: P4 minor
Assignee: Damien Miller
URL:
Keywords: low-hanging-fruit, needs-release-note, patch
Depends on:
Blocks: V_4_8
  Show dependency treegraph
 
Reported: 2003-12-20 20:06 AEDT by Chad
Modified: 2023-01-13 13:57 AEDT (History)
1 user (show)

See Also:


Attachments
Report error on read/write failures (deleted)
2007-05-17 18:41 AEST, Damien Miller
no flags Details
Permit escaping of glob characters (616 bytes, patch)
2007-05-18 17:37 AEST, Damien Miller
no flags Details | Diff
Diff with support for unquoted, escaped whitespace (6.34 KB, patch)
2007-05-20 22:18 AEST, Damien Miller
no flags Details | Diff
Rewrite sftp command parsing and glob handling (12.90 KB, patch)
2007-09-21 14:59 AEST, Damien Miller
no flags Details | Diff
Tweaked diff with regress tests (16.83 KB, patch)
2007-09-21 18:11 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 Chad 2003-12-20 20:06:30 AEDT
sftp client uses glob() to glob the absolute path + relative path.  In the 
scenario where the current working directory is something like "/tmp/
[testdir]", and you try to retrieve a file "testfile.txt" from that directory 
doing a get "testfile.txt" or mget "testfile.txt" then sftp client prepends the 
cwd and the arguments to get and then passes them to a globbing routine.  
Making it difficult to retrieve files from a directory enclosed in square 
brackets.  sftp should probably not glob at all when using get/put, and only 
glob the arguments to mget/mput <not the current working directory>.
Comment 1 Damien Miller 2007-05-17 18:41:41 AEST
Created attachment 1284 [details]
Report error on read/write failures

I'm not sure how much logspam this patch will generate, so I'm going to run with it for a little while.
Comment 2 Damien Miller 2007-05-17 18:42:16 AEST
The content of attachment 1284 [details] has been deleted by
    Damien Miller <djm@mindrot.org>
who provided the following reason:

wrong bug

The token used to delete this attachment was generated at 2007-05-17 18:42:08.
Comment 3 Damien Miller 2007-05-18 17:37:21 AEST
Created attachment 1291 [details]
Permit escaping of glob characters

This patch allows escaping of glob characters, so you should be able to do:

put "file with \[square braces]"
put "file with asterisk\*"

and so forth.
Comment 4 Damien Miller 2007-05-20 22:18:10 AEST
Created attachment 1295 [details]
Diff with support for unquoted, escaped whitespace

This diff merges the previous diff with one from Ben Lindstrom to add support for escaping of whitespace in unquoted filenames. So this will support all of:

get "filename with \[glob metacharacters]"
get filename\ with\ spaces
get filename\ with\ spaces\ and\ \[glob metacharacters]
Comment 5 Damien Miller 2007-09-21 14:59:06 AEST
Created attachment 1357 [details]
Rewrite sftp command parsing and glob handling

I think this patch is correct: it rewrites sftp's command parsing code to split the string into an argv using sh(1)-like rules, and should handle glob sequences much more naturally.

Things like 'rm \*' and 'rm "*"' should work now (i.e. they are not equivalent to 'rm *'), as should more complicated sequences like 'put "[some files] - blah"*'

It does need some regress tests though.
Comment 6 Damien Miller 2007-09-21 18:11:14 AEST
Created attachment 1358 [details]
Tweaked diff with regress tests

The previous diff had a small bug related to glob's handling of backslash characters. This version also adds some regression tests.
Comment 7 Damien Miller 2007-09-21 18:11:47 AEST
Put this on the radar for 4.8
Comment 8 Damien Miller 2007-10-24 13:48:06 AEST
patch is applied - will be in openssh-4.8

This will need a release note, as scripts that depended on the previous broken behaviour may need to change.
Comment 9 Damien Miller 2008-03-31 15:19:54 AEDT
Fix shipped in 4.9/4.9p1 release.