diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-10 22:14:51 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-10 22:14:51 +0000 |
commit | 52ce533c5f826a0e0cbee12fda81ec8952a19563 (patch) | |
tree | 598fd24a42bb39209d33d3893ee75dde5a0c36c7 /net/ftp | |
parent | b41e128346c40993507bc473dc4218516acda837 (diff) | |
download | chromium_src-52ce533c5f826a0e0cbee12fda81ec8952a19563.zip chromium_src-52ce533c5f826a0e0cbee12fda81ec8952a19563.tar.gz chromium_src-52ce533c5f826a0e0cbee12fda81ec8952a19563.tar.bz2 |
FTP: allow garbage instead of "ls -l" permissions listing.
Some broken servers send garbage in that place,
and we still can parse the rest of the line.
BUG=none
Review URL: https://chromiumcodereview.appspot.com/11475039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@172149 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/ftp')
-rw-r--r-- | net/ftp/ftp_directory_listing_parser_ls.cc | 45 | ||||
-rw-r--r-- | net/ftp/ftp_directory_listing_parser_ls_unittest.cc | 18 |
2 files changed, 17 insertions, 46 deletions
diff --git a/net/ftp/ftp_directory_listing_parser_ls.cc b/net/ftp/ftp_directory_listing_parser_ls.cc index 1257d5a..9657ccd 100644 --- a/net/ftp/ftp_directory_listing_parser_ls.cc +++ b/net/ftp/ftp_directory_listing_parser_ls.cc @@ -16,42 +16,6 @@ namespace { -bool LooksLikeUnixPermission(const string16& text) { - if (text.length() != 3) - return false; - - // Meaning of the flags: - // r - file is readable - // w - file is writable - // x - file is executable - // s, S or l - setuid/setgid bit set - // t or T - "sticky" bit set - return ((text[0] == 'r' || text[0] == '-') && - (text[1] == 'w' || text[1] == '-') && - (text[2] == 'x' || text[2] == '-' || - text[2] == 's' || text[2] == 'S' || text[2] == 'l' || - text[2] == 't' || text[2] == 'T')); -} - -bool LooksLikeUnixPermissionsListing(const string16& text) { - if (text.length() < 7) - return false; - - // Do not check the first character (entry type). There are many weird - // servers that use special file types (for example Plan9 and append-only - // files). Fortunately, the rest of the permission listing is more consistent. - - // Do not check the rest of the string. Some servers fail to properly - // separate this column from the next column (number of links), resulting - // in additional characters at the end. Also, sometimes there is a "+" - // sign at the end indicating the file has ACLs set. - - // In fact, we don't even expect three "rwx" triplets of permission - // listing, as some FTP servers like Hylafax only send two. - return (LooksLikeUnixPermission(text.substr(1, 3)) && - LooksLikeUnixPermission(text.substr(4, 3))); -} - bool TwoColumnDateListingToTime(const string16& date, const string16& time, base::Time* result) { @@ -209,11 +173,12 @@ bool ParseFtpDirectoryListingLs( return false; } - if (!LooksLikeUnixPermissionsListing(columns[0])) - return false; - if (columns[0][0] == 'l') { + // Do not check "validity" of the permission listing. It's quirky, + // and some servers send garbage here while other parts of the line are OK. + + if (!columns[0].empty() && columns[0][0] == 'l') { entry.type = FtpDirectoryListingEntry::SYMLINK; - } else if (columns[0][0] == 'd') { + } else if (!columns[0].empty() && columns[0][0] == 'd') { entry.type = FtpDirectoryListingEntry::DIRECTORY; } else { entry.type = FtpDirectoryListingEntry::FILE; diff --git a/net/ftp/ftp_directory_listing_parser_ls_unittest.cc b/net/ftp/ftp_directory_listing_parser_ls_unittest.cc index 456fb6e..92431bc 100644 --- a/net/ftp/ftp_directory_listing_parser_ls_unittest.cc +++ b/net/ftp/ftp_directory_listing_parser_ls_unittest.cc @@ -136,6 +136,18 @@ TEST_F(FtpDirectoryListingParserLsTest, Good) { "Shortcut to incoming.lnk -> /t11/member/incoming", FtpDirectoryListingEntry::SYMLINK, "Shortcut to incoming.lnk", -1, 2007, 2, 8, 0, 0 }, + + // Garbage in permissions (with no effect on other bits). + // Also test multiple "columns" resulting from the garbage. + { "garbage 1 ftp ftp 528 Nov 01 2007 README", + FtpDirectoryListingEntry::FILE, "README", 528, + 2007, 11, 1, 0, 0 }, + { "gar bage 1 ftp ftp 528 Nov 01 2007 README", + FtpDirectoryListingEntry::FILE, "README", 528, + 2007, 11, 1, 0, 0 }, + { "g a r b a g e 1 ftp ftp 528 Nov 01 2007 README", + FtpDirectoryListingEntry::FILE, "README", 528, + 2007, 11, 1, 0, 0 }, }; for (size_t i = 0; i < arraysize(good_cases); i++) { SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, @@ -182,17 +194,11 @@ TEST_F(FtpDirectoryListingParserLsTest, Bad) { " foo", "garbage", "-rw-r--r-- ftp ftp", - "-rw-rgbr-- ftp ftp 528 Nov 01 2007 README", - "qrwwr--r-- ftp ftp 528 Nov 01 2007 README", "-rw-r--r-- ftp ftp 528 Foo 01 2007 README", "-rw-r--r-- 1 ftp ftp", - "-rw-rgbr-- 1 ftp ftp 528 Nov 01 2007 README", - "qrwwr--r-- 1 ftp ftp 528 Nov 01 2007 README", "-rw-r--r-- 1 ftp ftp 528 Foo 01 2007 README", "drwxrwxrwx 1 owner group 1024 Sep 13 0:3 audio", - "-qqqqqqqqq+ 2 sys 512 Mar 27 2009 pub", - // Invalid month value (30). "drwxrwxrwx 2 root root 4096 2012-30-07 00:31 notas_servico", }; |