summaryrefslogtreecommitdiffstats
path: root/net/ftp
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-06 21:09:29 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-06 21:09:29 +0000
commit9edd6e1119f6a22fd475a18df105d5ad34ad6d00 (patch)
tree31cb6078aca2c18f5d403693737d0d10cdb6ebb0 /net/ftp
parentc0d5f8e79408e3d087612e4c58fc17aa0af3ed27 (diff)
downloadchromium_src-9edd6e1119f6a22fd475a18df105d5ad34ad6d00.zip
chromium_src-9edd6e1119f6a22fd475a18df105d5ad34ad6d00.tar.gz
chromium_src-9edd6e1119f6a22fd475a18df105d5ad34ad6d00.tar.bz2
Properly handle invalid server control responses.
We should immediately stop the ftp network transaction in such case. TEST=Covered by net_unittests. http://crbug.com/18546 Review URL: http://codereview.chromium.org/164067 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22664 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/ftp')
-rw-r--r--net/ftp/ftp_network_transaction.cc2
-rw-r--r--net/ftp/ftp_network_transaction_unittest.cc27
2 files changed, 28 insertions, 1 deletions
diff --git a/net/ftp/ftp_network_transaction.cc b/net/ftp/ftp_network_transaction.cc
index e3b2709..8bb35fc 100644
--- a/net/ftp/ftp_network_transaction.cc
+++ b/net/ftp/ftp_network_transaction.cc
@@ -196,7 +196,7 @@ int FtpNetworkTransaction::ProcessCtrlResponse() {
break;
default:
// Multiple responses for other commands are invalid.
- return ERR_INVALID_RESPONSE;
+ return Stop(ERR_INVALID_RESPONSE);
}
}
diff --git a/net/ftp/ftp_network_transaction_unittest.cc b/net/ftp/ftp_network_transaction_unittest.cc
index cc9c1bb..a7ea82c 100644
--- a/net/ftp/ftp_network_transaction_unittest.cc
+++ b/net/ftp/ftp_network_transaction_unittest.cc
@@ -232,6 +232,29 @@ class FtpMockControlSocketFileDownloadTransferStarting
DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketFileDownloadTransferStarting);
};
+class FtpMockControlSocketFileDownloadInvalidResponse
+ : public FtpMockControlSocketFileDownload {
+ public:
+ FtpMockControlSocketFileDownloadInvalidResponse() {
+ }
+
+ virtual MockWriteResult OnWrite(const std::string& data) {
+ if (InjectFault())
+ return MockWriteResult(true, data.length());
+ switch (state()) {
+ case PRE_SIZE:
+ return Verify("SIZE /file\r\n", data, PRE_QUIT,
+ "500 Evil Response\r\n"
+ "500 More Evil\r\n");
+ default:
+ return FtpMockControlSocketFileDownload::OnWrite(data);
+ }
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(FtpMockControlSocketFileDownloadInvalidResponse);
+};
+
class FtpMockControlSocketFileDownloadRetrFail
: public FtpMockControlSocketFileDownload {
public:
@@ -385,6 +408,10 @@ TEST_F(FtpNetworkTransactionTest, DownloadTransactionTransferStarting) {
ExecuteTransaction(&ctrl_socket, "ftp://host/file", OK);
}
+TEST_F(FtpNetworkTransactionTest, DownloadTransactionInvalidResponse) {
+ FtpMockControlSocketFileDownloadInvalidResponse ctrl_socket;
+ ExecuteTransaction(&ctrl_socket, "ftp://host/file", ERR_INVALID_RESPONSE);
+}
TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailUser) {
FtpMockControlSocketDirectoryListing ctrl_socket;