summaryrefslogtreecommitdiffstats
path: root/net/socket/socks5_client_socket.cc
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-18 23:43:43 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-18 23:43:43 +0000
commit866ba4c8103f3ebde2c1bb15a325dae0edf885f7 (patch)
tree8c2675a7474c5ad2929ca2ab3e81d65266f185d6 /net/socket/socks5_client_socket.cc
parent6d27a7b2473b8c7b83f55a43eb597f2595007a12 (diff)
downloadchromium_src-866ba4c8103f3ebde2c1bb15a325dae0edf885f7.zip
chromium_src-866ba4c8103f3ebde2c1bb15a325dae0edf885f7.tar.gz
chromium_src-866ba4c8103f3ebde2c1bb15a325dae0edf885f7.tar.bz2
Add two more unit tests for SOCKS5:
* Check that connecting again after having disconnected works. * Check that trying to connect with a very large hostname fails. Also removes some unused code from socks_client_socket.cc. BUG=NONE Review URL: http://codereview.chromium.org/501112 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35008 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket/socks5_client_socket.cc')
-rw-r--r--net/socket/socks5_client_socket.cc12
1 files changed, 7 insertions, 5 deletions
diff --git a/net/socket/socks5_client_socket.cc b/net/socket/socks5_client_socket.cc
index 7386caf..33d8e53 100644
--- a/net/socket/socks5_client_socket.cc
+++ b/net/socket/socks5_client_socket.cc
@@ -85,7 +85,7 @@ bool SOCKS5ClientSocket::IsConnectedAndIdle() const {
// Read is called by the transport layer above to read. This can only be done
// if the SOCKS handshake is complete.
int SOCKS5ClientSocket::Read(IOBuffer* buf, int buf_len,
- CompletionCallback* callback) {
+ CompletionCallback* callback) {
DCHECK(completed_handshake_);
DCHECK_EQ(STATE_NONE, next_state_);
DCHECK(!user_callback_);
@@ -182,6 +182,11 @@ const char kSOCKS5GreetWriteData[] = { 0x05, 0x01, 0x00 }; // no authentication
const char kSOCKS5GreetReadData[] = { 0x05, 0x00 };
int SOCKS5ClientSocket::DoGreetWrite() {
+ // Since we only have 1 byte to send the hostname length in, if the
+ // URL has a hostname longer than 255 characters we can't send it.
+ if (0xFF < host_request_info_.hostname().size())
+ return ERR_INVALID_URL;
+
if (buffer_.empty()) {
buffer_ = std::string(kSOCKS5GreetWriteData,
arraysize(kSOCKS5GreetWriteData));
@@ -251,10 +256,7 @@ int SOCKS5ClientSocket::BuildHandshakeWriteBuffer(std::string* handshake)
handshake->push_back(kEndPointDomain); // The type of the address.
- // We only have 1 byte to send the length in, so if the hostname is
- // longer than this we can't send it!
- if(256 <= host_request_info_.hostname().size())
- return ERR_INVALID_URL;
+ DCHECK_GE(static_cast<size_t>(0xFF), host_request_info_.hostname().size());
// First add the size of the hostname, followed by the hostname.
handshake->push_back(static_cast<unsigned char>(