summaryrefslogtreecommitdiffstats
path: root/net/ftp
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-28 07:17:42 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-28 07:17:42 +0000
commit9aefe33e2aca99fe6d00b23e5904c3d006211d4e (patch)
tree4fde4ccf3d48a03eec1ae15a9478ee2b062c451d /net/ftp
parent2ef43e9b67ff014bf3939cf0153464e015990bb8 (diff)
downloadchromium_src-9aefe33e2aca99fe6d00b23e5904c3d006211d4e.zip
chromium_src-9aefe33e2aca99fe6d00b23e5904c3d006211d4e.tar.gz
chromium_src-9aefe33e2aca99fe6d00b23e5904c3d006211d4e.tar.bz2
FTP: fix directory listing parser for ftp://ftp.dd-wrt.com/others/juno6/
Now the "ls -l" parser ignores lines with empty file names instead of failing. BUG=60065 TEST=net_unittests Review URL: http://codereview.chromium.org/4182002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64208 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/ftp')
-rw-r--r--net/ftp/ftp_directory_listing_buffer_unittest.cc1
-rw-r--r--net/ftp/ftp_directory_listing_parser_ls.cc24
-rw-r--r--net/ftp/ftp_directory_listing_parser_ls_unittest.cc28
3 files changed, 45 insertions, 8 deletions
diff --git a/net/ftp/ftp_directory_listing_buffer_unittest.cc b/net/ftp/ftp_directory_listing_buffer_unittest.cc
index 86fc6e7..683e2f7 100644
--- a/net/ftp/ftp_directory_listing_buffer_unittest.cc
+++ b/net/ftp/ftp_directory_listing_buffer_unittest.cc
@@ -41,6 +41,7 @@ TEST(FtpDirectoryListingBufferTest, Parse) {
"dir-listing-ls-16",
"dir-listing-ls-17",
"dir-listing-ls-18",
+ "dir-listing-ls-19",
"dir-listing-mlsd-1",
"dir-listing-mlsd-2",
"dir-listing-netware-1",
diff --git a/net/ftp/ftp_directory_listing_parser_ls.cc b/net/ftp/ftp_directory_listing_parser_ls.cc
index 89fc3d8..40546c8 100644
--- a/net/ftp/ftp_directory_listing_parser_ls.cc
+++ b/net/ftp/ftp_directory_listing_parser_ls.cc
@@ -126,8 +126,20 @@ bool FtpDirectoryListingParserLs::ConsumeLine(const string16& line) {
// We may receive file names containing spaces, which can make the number of
// columns arbitrarily large. We will handle that later. For now just make
- // sure we have all the columns that should normally be there.
- if (columns.size() < 7U + column_offset)
+ // sure we have all the columns that should normally be there:
+ //
+ // 1. permission listing
+ // 2. number of links (optional)
+ // 3. owner name
+ // 4. group name (optional)
+ // 5. size in bytes
+ // 6. month
+ // 7. day of month
+ // 8. year or time
+ //
+ // The number of optional columns is stored in |column_offset|
+ // and is between 0 and 2 (inclusive).
+ if (columns.size() < 6U + column_offset)
return false;
if (!LooksLikeUnixPermissionsListing(columns[0]))
@@ -165,6 +177,14 @@ bool FtpDirectoryListingParserLs::ConsumeLine(const string16& line) {
}
entry.name = FtpUtil::GetStringPartAfterColumns(line, 6 + column_offset);
+
+ if (entry.name.empty()) {
+ // Some FTP servers send listing entries with empty names. It's not obvious
+ // how to display such an entry, so we ignore them. We don't want to make
+ // the parsing fail at this point though. Other entries can still be useful.
+ return true;
+ }
+
if (entry.type == FtpDirectoryListingEntry::SYMLINK) {
string16::size_type pos = entry.name.rfind(ASCIIToUTF16(" -> "));
diff --git a/net/ftp/ftp_directory_listing_parser_ls_unittest.cc b/net/ftp/ftp_directory_listing_parser_ls_unittest.cc
index 4b36544..3e777cc 100644
--- a/net/ftp/ftp_directory_listing_parser_ls_unittest.cc
+++ b/net/ftp/ftp_directory_listing_parser_ls_unittest.cc
@@ -91,6 +91,28 @@ TEST_F(FtpDirectoryListingParserLsTest, Good) {
}
}
+TEST_F(FtpDirectoryListingParserLsTest, Ignored) {
+ const char* ignored_cases[] = {
+ "drwxr-xr-x 2 0 0 4096 Mar 18 2007 ", // http://crbug.com/60065
+
+ // Tests important for security: verify that after we detect the column
+ // offset we don't try to access invalid memory on malformed input.
+ "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11",
+ "drwxr-xr-x 3 ftp 4096 May 15 18:11",
+ "drwxr-xr-x folder 0 May 15 18:11",
+ };
+ for (size_t i = 0; i < arraysize(ignored_cases); i++) {
+ SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i,
+ ignored_cases[i]));
+
+ net::FtpDirectoryListingParserLs parser(GetMockCurrentTime());
+ EXPECT_TRUE(parser.ConsumeLine(UTF8ToUTF16(ignored_cases[i])));
+ EXPECT_FALSE(parser.EntryAvailable());
+ EXPECT_TRUE(parser.OnEndOfInput());
+ EXPECT_FALSE(parser.EntryAvailable());
+ }
+}
+
TEST_F(FtpDirectoryListingParserLsTest, Bad) {
const char* bad_cases[] = {
" foo",
@@ -112,12 +134,6 @@ TEST_F(FtpDirectoryListingParserLsTest, Bad) {
"d-wx-wx-wt++ 4 ftp 989 512 Dec 8 15:54 incoming",
"d-wx-wx-wt$ 4 ftp 989 512 Dec 8 15:54 incoming",
"-qqqqqqqqq+ 2 sys 512 Mar 27 2009 pub",
-
- // Tests important for security: verify that after we detect the column
- // offset we don't try to access invalid memory on malformed input.
- "drwxr-xr-x 3 ftp ftp 4096 May 15 18:11",
- "drwxr-xr-x 3 ftp 4096 May 15 18:11",
- "drwxr-xr-x folder 0 May 15 18:11",
};
for (size_t i = 0; i < arraysize(bad_cases); i++) {
net::FtpDirectoryListingParserLs parser(GetMockCurrentTime());