summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-04 19:59:29 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-04 19:59:29 +0000
commitcd4857b64f3e3b10ebfa3f44c38af0dc7376d5bb (patch)
tree673df096ae1c340fe879910f5f5625d078d3e5ba /net
parent71055d30f11af1ad8427d7e96c105bf79010ab16 (diff)
downloadchromium_src-cd4857b64f3e3b10ebfa3f44c38af0dc7376d5bb.zip
chromium_src-cd4857b64f3e3b10ebfa3f44c38af0dc7376d5bb.tar.gz
chromium_src-cd4857b64f3e3b10ebfa3f44c38af0dc7376d5bb.tar.bz2
FTP: correctly handle directory listings containing "Permission denied" errors.
BUG=67797 TEST=net_unittests Review URL: http://codereview.chromium.org/6096006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70435 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/data/ftp/dir-listing-ls-232
-rw-r--r--net/data/ftp/dir-listing-ls-23.expected0
-rw-r--r--net/ftp/ftp_directory_listing_buffer_unittest.cc1
-rw-r--r--net/ftp/ftp_directory_listing_parser_ls.cc23
-rw-r--r--net/ftp/ftp_directory_listing_parser_ls_unittest.cc3
5 files changed, 27 insertions, 2 deletions
diff --git a/net/data/ftp/dir-listing-ls-23 b/net/data/ftp/dir-listing-ls-23
new file mode 100644
index 0000000..2b8c494
--- /dev/null
+++ b/net/data/ftp/dir-listing-ls-23
@@ -0,0 +1,2 @@
+total 0
+ftpd: .: Permission denied
diff --git a/net/data/ftp/dir-listing-ls-23.expected b/net/data/ftp/dir-listing-ls-23.expected
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/net/data/ftp/dir-listing-ls-23.expected
diff --git a/net/ftp/ftp_directory_listing_buffer_unittest.cc b/net/ftp/ftp_directory_listing_buffer_unittest.cc
index cb120a6..81e72c1 100644
--- a/net/ftp/ftp_directory_listing_buffer_unittest.cc
+++ b/net/ftp/ftp_directory_listing_buffer_unittest.cc
@@ -42,6 +42,7 @@ TEST(FtpDirectoryListingBufferTest, Parse) {
"dir-listing-ls-20", // TODO(phajdan.jr): should use windows-1251 encoding.
"dir-listing-ls-21", // TODO(phajdan.jr): should use windows-1251 encoding.
"dir-listing-ls-22", // TODO(phajdan.jr): should use windows-1251 encoding.
+ "dir-listing-ls-23",
"dir-listing-netware-1",
"dir-listing-netware-2",
"dir-listing-vms-1",
diff --git a/net/ftp/ftp_directory_listing_parser_ls.cc b/net/ftp/ftp_directory_listing_parser_ls.cc
index 9660eab..34ef519 100644
--- a/net/ftp/ftp_directory_listing_parser_ls.cc
+++ b/net/ftp/ftp_directory_listing_parser_ls.cc
@@ -45,6 +45,21 @@ bool LooksLikeUnixPermissionsListing(const string16& text) {
(text.substr(10).empty() || text.substr(10) == ASCIIToUTF16("+")));
}
+bool LooksLikePermissionDeniedError(const string16& text) {
+ // Try to recognize a three-part colon-separated error message:
+ //
+ // 1. ftpd server name
+ // 2. directory name (often just ".")
+ // 3. message text (usually "Permission denied")
+ std::vector<string16> parts;
+ base::SplitString(CollapseWhitespace(text, false), ':', &parts);
+
+ if (parts.size() != 3)
+ return false;
+
+ return parts[2] == ASCIIToUTF16("Permission denied");
+}
+
bool DetectColumnOffset(const std::vector<string16>& columns,
const base::Time& current_time, int* offset) {
base::Time time;
@@ -125,8 +140,12 @@ bool FtpDirectoryListingParserLs::ConsumeLine(const string16& line) {
}
int column_offset;
- if (!DetectColumnOffset(columns, current_time_, &column_offset))
- return false;
+ if (!DetectColumnOffset(columns, current_time_, &column_offset)) {
+ // If we can't recognize a normal listing line, maybe it's an error?
+ // In that case, just ignore the error, but still recognize the data
+ // as valid listing.
+ return LooksLikePermissionDeniedError(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
diff --git a/net/ftp/ftp_directory_listing_parser_ls_unittest.cc b/net/ftp/ftp_directory_listing_parser_ls_unittest.cc
index 3e777cc..ea4f094 100644
--- a/net/ftp/ftp_directory_listing_parser_ls_unittest.cc
+++ b/net/ftp/ftp_directory_listing_parser_ls_unittest.cc
@@ -95,6 +95,9 @@ TEST_F(FtpDirectoryListingParserLsTest, Ignored) {
const char* ignored_cases[] = {
"drwxr-xr-x 2 0 0 4096 Mar 18 2007 ", // http://crbug.com/60065
+ "ftpd: .: Permission denied",
+ "ftpd-BSD: .: Permission denied",
+
// 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",