summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authormbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-19 15:45:45 +0000
committermbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-19 15:45:45 +0000
commit09883d6c1351e52e318e7e5c1b9165afe6a1e9bc (patch)
tree8b8ce35783e10ef07af35fac8eea4db257d24e3c /net
parent9e3053496afc41d6dd1da4cb67926cd66d64189d (diff)
downloadchromium_src-09883d6c1351e52e318e7e5c1b9165afe6a1e9bc.zip
chromium_src-09883d6c1351e52e318e7e5c1b9165afe6a1e9bc.tar.gz
chromium_src-09883d6c1351e52e318e7e5c1b9165afe6a1e9bc.tar.bz2
Prevent crash in test case where tests could overflow the index to the list of
test socket types to create. The backup sockets fire at ~250ms. So, if the test takes longer than expected, it will end up creating more sockets than the test case expects, and we could overflow this list. We may need to do more work to make it so this never happens, but this will prevent the crash. BUG=43919 TEST=TCPClientSocketPoolTest.BackupSocketConnect Review URL: http://codereview.chromium.org/2072006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47669 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/socket/tcp_client_socket_pool_unittest.cc18
1 files changed, 12 insertions, 6 deletions
diff --git a/net/socket/tcp_client_socket_pool_unittest.cc b/net/socket/tcp_client_socket_pool_unittest.cc
index fdd8e6e..9fd1c8a 100644
--- a/net/socket/tcp_client_socket_pool_unittest.cc
+++ b/net/socket/tcp_client_socket_pool_unittest.cc
@@ -194,15 +194,18 @@ class MockClientSocketFactory : public ClientSocketFactory {
MockClientSocketFactory()
: allocation_count_(0), client_socket_type_(MOCK_CLIENT_SOCKET),
- client_socket_types_(NULL), client_socket_index_(0) {}
+ client_socket_types_(NULL), client_socket_index_(0),
+ client_socket_index_max_(0) {}
virtual ClientSocket* CreateTCPClientSocket(const AddressList& addresses,
NetLog* /* net_log */) {
allocation_count_++;
ClientSocketType type = client_socket_type_;
- if (client_socket_types_)
+ if (client_socket_types_ &&
+ client_socket_index_ < client_socket_index_max_) {
type = client_socket_types_[client_socket_index_++];
+ }
switch (type) {
case MOCK_CLIENT_SOCKET:
@@ -240,9 +243,11 @@ class MockClientSocketFactory : public ClientSocketFactory {
}
// Set a list of ClientSocketTypes to be used.
- void set_client_socket_types(ClientSocketType* type_list) {
+ void set_client_socket_types(ClientSocketType* type_list, int num_types) {
+ DCHECK_GT(num_types, 0);
client_socket_types_ = type_list;
client_socket_index_ = 0;
+ client_socket_index_max_ = num_types;
}
private:
@@ -250,6 +255,7 @@ class MockClientSocketFactory : public ClientSocketFactory {
ClientSocketType client_socket_type_;
ClientSocketType* client_socket_types_;
int client_socket_index_;
+ int client_socket_index_max_;
};
class TCPClientSocketPoolTest : public ClientSocketPoolTest {
@@ -673,7 +679,7 @@ TEST_F(TCPClientSocketPoolTest, BackupSocketConnect) {
};
for (size_t index = 0; index < arraysize(cases); ++index) {
- client_socket_factory_.set_client_socket_types(cases[index]);
+ client_socket_factory_.set_client_socket_types(cases[index], 2);
EXPECT_EQ(0, pool_->IdleSocketCount());
@@ -762,7 +768,7 @@ TEST_F(TCPClientSocketPoolTest, BackupSocketFailAfterStall) {
MockClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET
};
- client_socket_factory_.set_client_socket_types(case_types);
+ client_socket_factory_.set_client_socket_types(case_types, 2);
EXPECT_EQ(0, pool_->IdleSocketCount());
@@ -808,7 +814,7 @@ TEST_F(TCPClientSocketPoolTest, BackupSocketFailAfterDelay) {
MockClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET
};
- client_socket_factory_.set_client_socket_types(case_types);
+ client_socket_factory_.set_client_socket_types(case_types, 2);
EXPECT_EQ(0, pool_->IdleSocketCount());