Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(604)

Side by Side Diff: net/ftp/ftp_network_transaction.cc

Issue 146137: Hang if directory listing size is > 8k (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #include "net/ftp/ftp_network_transaction.h" 5 #include "net/ftp/ftp_network_transaction.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "net/base/connection_type_histograms.h" 9 #include "net/base/connection_type_histograms.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 CompletionCallback* callback) { 81 CompletionCallback* callback) {
82 return ERR_FAILED; 82 return ERR_FAILED;
83 } 83 }
84 84
85 int FtpNetworkTransaction::Read(IOBuffer* buf, 85 int FtpNetworkTransaction::Read(IOBuffer* buf,
86 int buf_len, 86 int buf_len,
87 CompletionCallback* callback) { 87 CompletionCallback* callback) {
88 DCHECK(buf); 88 DCHECK(buf);
89 DCHECK(buf_len > 0); 89 DCHECK(buf_len > 0);
90 90
91 if (data_socket_ == NULL)
92 return 0; // Data socket closed, no more data left.
93
94 if (!data_socket_->IsConnected())
95 return 0; // Data socket disconnected, no more data left.
96
97 read_data_buf_ = buf; 91 read_data_buf_ = buf;
98 read_data_buf_len_ = buf_len; 92 // Always read one byte less than the size, because if data is directory
99 93 // listing then we must have a null terminating string.
94 read_data_buf_len_ = buf_len - 1;
100 next_state_ = STATE_DATA_READ; 95 next_state_ = STATE_DATA_READ;
101 96
102 int rv = DoLoop(OK); 97 int rv = DoLoop(OK);
103 if (rv == ERR_IO_PENDING) 98 if (rv == ERR_IO_PENDING)
104 user_callback_ = callback; 99 user_callback_ = callback;
105 else if (rv == 0)
106 data_socket_->Disconnect();
107 return rv; 100 return rv;
108 } 101 }
109 102
110 const FtpResponseInfo* FtpNetworkTransaction::GetResponseInfo() const { 103 const FtpResponseInfo* FtpNetworkTransaction::GetResponseInfo() const {
111 return &response_; 104 return &response_;
112 } 105 }
113 106
114 LoadState FtpNetworkTransaction::GetLoadState() const { 107 LoadState FtpNetworkTransaction::GetLoadState() const {
115 return LOAD_STATE_IDLE; 108 return LOAD_STATE_IDLE;
116 } 109 }
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 // LIST command 781 // LIST command
789 int FtpNetworkTransaction::DoCtrlWriteLIST() { 782 int FtpNetworkTransaction::DoCtrlWriteLIST() {
790 std::string command = "LIST"; 783 std::string command = "LIST";
791 next_state_ = STATE_CTRL_READ; 784 next_state_ = STATE_CTRL_READ;
792 return SendFtpCommand(command, COMMAND_LIST); 785 return SendFtpCommand(command, COMMAND_LIST);
793 } 786 }
794 787
795 int FtpNetworkTransaction::ProcessResponseLIST(int response_code) { 788 int FtpNetworkTransaction::ProcessResponseLIST(int response_code) {
796 switch (GetErrorClass(response_code)) { 789 switch (GetErrorClass(response_code)) {
797 case ERROR_CLASS_INITIATED: 790 case ERROR_CLASS_INITIATED:
791 response_.is_directory_listing = true;
798 response_message_buf_len_ = 0; // Clear the responce buffer. 792 response_message_buf_len_ = 0; // Clear the responce buffer.
799 next_state_ = STATE_CTRL_READ;
800 break; 793 break;
801 case ERROR_CLASS_OK: 794 case ERROR_CLASS_OK:
802 response_.is_directory_listing = true; 795 response_.is_directory_listing = true;
803 next_state_ = STATE_CTRL_WRITE_QUIT; 796 next_state_ = STATE_CTRL_WRITE_QUIT;
804 break; 797 break;
805 case ERROR_CLASS_PENDING: 798 case ERROR_CLASS_PENDING:
806 return Stop(ERR_FAILED); 799 return Stop(ERR_FAILED);
807 case ERROR_CLASS_ERROR_RETRY: 800 case ERROR_CLASS_ERROR_RETRY:
808 return Stop(ERR_FAILED); 801 return Stop(ERR_FAILED);
809 case ERROR_CLASS_ERROR: 802 case ERROR_CLASS_ERROR:
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 int FtpNetworkTransaction::DoDataConnectComplete(int result) { 851 int FtpNetworkTransaction::DoDataConnectComplete(int result) {
859 if (retr_failed_) { 852 if (retr_failed_) {
860 next_state_ = STATE_CTRL_WRITE_CWD; 853 next_state_ = STATE_CTRL_WRITE_CWD;
861 } else { 854 } else {
862 next_state_ = STATE_CTRL_WRITE_SIZE; 855 next_state_ = STATE_CTRL_WRITE_SIZE;
863 } 856 }
864 return OK; 857 return OK;
865 } 858 }
866 859
867 int FtpNetworkTransaction::DoDataRead() { 860 int FtpNetworkTransaction::DoDataRead() {
861 if (data_socket_ == NULL || !data_socket_->IsConnected())
862 return Stop(OK); // No more data so send QUIT Command now and wait for resp onse.
863
868 DCHECK(read_data_buf_); 864 DCHECK(read_data_buf_);
869 DCHECK(read_data_buf_len_ > 0); 865 DCHECK(read_data_buf_len_ > 0);
870 866
871 next_state_ = STATE_DATA_READ_COMPLETE; 867 next_state_ = STATE_DATA_READ_COMPLETE;
872 read_data_buf_->data()[0] = 0; 868 read_data_buf_->data()[0] = 0;
873 return data_socket_->Read(read_data_buf_, read_data_buf_len_, 869 return data_socket_->Read(read_data_buf_, read_data_buf_len_,
874 &io_callback_); 870 &io_callback_);
875 } 871 }
876 872
877 int FtpNetworkTransaction::DoDataReadComplete(int result) { 873 int FtpNetworkTransaction::DoDataReadComplete(int result) {
878 DLOG(INFO) << read_data_buf_->data(); // The read_data_buf_ is NULL
879 // terminated string.
880 return result; 874 return result;
881 } 875 }
882 876
883 } // namespace net 877 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698