diff options
author | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-20 00:03:29 +0000 |
---|---|---|
committer | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-20 00:03:29 +0000 |
commit | 93d5829fc79a8aaa736106271e78364369a942eb (patch) | |
tree | e9c895e58905a2031940168f7e18bc203bd64cb1 /net | |
parent | 168a71dcdbde91f44b9d8673951366786ff5182f (diff) | |
download | chromium_src-93d5829fc79a8aaa736106271e78364369a942eb.zip chromium_src-93d5829fc79a8aaa736106271e78364369a942eb.tar.gz chromium_src-93d5829fc79a8aaa736106271e78364369a942eb.tar.bz2 |
Don't put CredHandleClass in std::map directly because
std::map may copy an entry to a new address while resizing,
which invokes the destructor on the old entry and invalidates
its address.
R=eroman
BUG=http://crbug.com/318
TEST=none
Review URL: http://codereview.chromium.org/141011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18879 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/ssl_client_socket_win.cc | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/net/base/ssl_client_socket_win.cc b/net/base/ssl_client_socket_win.cc index 3517adc..9cfdfb2 100644 --- a/net/base/ssl_client_socket_win.cc +++ b/net/base/ssl_client_socket_win.cc @@ -8,6 +8,7 @@ #include "base/lock.h" #include "base/singleton.h" +#include "base/stl_util-inl.h" #include "base/string_util.h" #include "net/base/connection_type_histograms.h" #include "net/base/io_buffer.h" @@ -80,8 +81,7 @@ enum { }; // CredHandleClass simply gives a default constructor and a destructor to -// SSPI's CredHandle type (a C struct). The default constuctor is required -// by STL containers. +// SSPI's CredHandle type (a C struct). class CredHandleClass : public CredHandle { public: CredHandleClass() { @@ -102,16 +102,25 @@ class CredHandleTable { public: CredHandleTable() {} - ~CredHandleTable() {} + ~CredHandleTable() { + STLDeleteContainerPairSecondPointers(client_cert_creds_.begin(), + client_cert_creds_.end()); + } CredHandle* GetHandle(PCCERT_CONTEXT client_cert, int ssl_version_mask) { DCHECK(0 < ssl_version_mask && ssl_version_mask < arraysize(anonymous_creds_)); - CredHandle* handle; + CredHandleClass* handle; AutoLock lock(lock_); if (client_cert) { - handle = &client_cert_creds_[ - std::make_pair(client_cert, ssl_version_mask)]; + CredHandleMapKey key = std::make_pair(client_cert, ssl_version_mask); + CredHandleMap::const_iterator it = client_cert_creds_.find(key); + if (it == client_cert_creds_.end()) { + handle = new CredHandleClass; + client_cert_creds_[key] = handle; + } else { + handle = it->second; + } } else { handle = &anonymous_creds_[ssl_version_mask]; } @@ -126,7 +135,7 @@ class CredHandleTable { // int ssl_version_mask typedef std::pair<PCCERT_CONTEXT, int> CredHandleMapKey; - typedef std::map<CredHandleMapKey, CredHandleClass> CredHandleMap; + typedef std::map<CredHandleMapKey, CredHandleClass*> CredHandleMap; static void InitializeHandle(CredHandle* handle, PCCERT_CONTEXT client_cert, |