Bug 1602009 - Make sure mSecurityObserver can be only accessed within a lock r=valentin
authorKershaw Chang <kershaw@mozilla.com>
Thu, 12 Dec 2019 13:42:43 +0000
changeset 506670 ac461b0e7204b9f8cc020a1d807e4ee5fd5d976a
parent 506669 ec7033e256bf6eb20ddb8d7bd6edf191693deca2
child 506671 68b0102b619ea3fa5eb5373a152f3a924e85576f
push id36910
push usercsabou@mozilla.com
push dateThu, 12 Dec 2019 21:50:40 +0000
treeherdermozilla-central@0f6958f49842 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1602009
milestone73.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1602009 - Make sure mSecurityObserver can be only accessed within a lock r=valentin Differential Revision: https://phabricator.services.mozilla.com/D56904
netwerk/base/TLSServerSocket.cpp
--- a/netwerk/base/TLSServerSocket.cpp
+++ b/netwerk/base/TLSServerSocket.cpp
@@ -274,20 +274,16 @@ TLSServerConnectionInfo::TLSServerConnec
       mPeerCert(nullptr),
       mTlsVersionUsed(TLS_VERSION_UNKNOWN),
       mKeyLength(0),
       mMacLength(0),
       mLock("TLSServerConnectionInfo.mLock"),
       mSecurityObserver(nullptr) {}
 
 TLSServerConnectionInfo::~TLSServerConnectionInfo() {
-  if (!mSecurityObserver) {
-    return;
-  }
-
   RefPtr<nsITLSServerSecurityObserver> observer;
   {
     MutexAutoLock lock(mLock);
     observer = mSecurityObserver.forget();
   }
 
   if (observer) {
     NS_ReleaseOnMainThreadSystemGroup(
@@ -416,24 +412,23 @@ nsresult TLSServerConnectionInfo::Handsh
                                            sizeof(cipherInfo)));
   if (NS_FAILED(rv)) {
     return rv;
   }
   mCipherName.Assign(cipherInfo.cipherSuiteName);
   mKeyLength = cipherInfo.effectiveKeyBits;
   mMacLength = cipherInfo.macBits;
 
-  if (!mSecurityObserver) {
-    return NS_OK;
-  }
-
   // Notify consumer code that handshake is complete
   nsCOMPtr<nsITLSServerSecurityObserver> observer;
   {
     MutexAutoLock lock(mLock);
+    if (!mSecurityObserver) {
+      return NS_OK;
+    }
     mSecurityObserver.swap(observer);
   }
   nsCOMPtr<nsITLSServerSocket> serverSocket;
   GetServerSocket(getter_AddRefs(serverSocket));
   observer->OnHandshakeDone(serverSocket, this);
 
   return NS_OK;
 }