Bug 1513458 - Add more specific MOZ_DIAGNOSTIC_ASSERTS to TransportSecurityInfo::Read in order to pinpoint crashes r=mayhemer
authorValentin Gosu <valentin.gosu@gmail.com>
Mon, 21 Jan 2019 18:12:12 +0000
changeset 454718 243733368484c9c41548d6acef5b6273be5f7948
parent 454717 a70ed4f3086ae9e117c3e46f99fd40122bc07dc6
child 454719 4aafc1f415adc5a3ab80630b94291968b3a84eb2
push id35411
push usercsabou@mozilla.com
push dateTue, 22 Jan 2019 03:53:40 +0000
treeherdermozilla-central@ada22b635f8d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1513458
milestone66.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 1513458 - Add more specific MOZ_DIAGNOSTIC_ASSERTS to TransportSecurityInfo::Read in order to pinpoint crashes r=mayhemer Differential Revision: https://phabricator.services.mozilla.com/D16828
security/manager/ssl/TransportSecurityInfo.cpp
--- a/security/manager/ssl/TransportSecurityInfo.cpp
+++ b/security/manager/ssl/TransportSecurityInfo.cpp
@@ -245,229 +245,275 @@ TransportSecurityInfo::Write(nsIObjectOu
   return NS_OK;
 }
 
 // This is for backward compatability to be able to read nsISSLStatus
 // serialized object.
 nsresult TransportSecurityInfo::ReadSSLStatus(nsIObjectInputStream* aStream) {
   bool nsISSLStatusPresent;
   nsresult rv = aStream->ReadBoolean(&nsISSLStatusPresent);
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
   NS_ENSURE_SUCCESS(rv, rv);
   if (!nsISSLStatusPresent) {
     return NS_OK;
   }
   // nsISSLStatus present.  Prepare to read elements.
   // Throw away cid, validate iid
   nsCID cid;
   nsIID iid;
   rv = aStream->ReadID(&cid);
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
   NS_ENSURE_SUCCESS(rv, rv);
   rv = aStream->ReadID(&iid);
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
   NS_ENSURE_SUCCESS(rv, rv);
 
   static const nsIID nsSSLStatusIID = {
       0xfa9ba95b,
       0xca3b,
       0x498a,
       {0xb8, 0x89, 0x7c, 0x79, 0xcf, 0x28, 0xfe, 0xe8}};
   if (!iid.Equals(nsSSLStatusIID)) {
+    MOZ_DIAGNOSTIC_ASSERT(false, "Deserialization should not fail");
     return NS_ERROR_UNEXPECTED;
   }
 
   nsCOMPtr<nsISupports> cert;
   rv = aStream->ReadObject(true, getter_AddRefs(cert));
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (cert) {
     mServerCert = do_QueryInterface(cert);
     if (!mServerCert) {
+      MOZ_DIAGNOSTIC_ASSERT(false,
+                            "Deserialization should not fail");
       return NS_NOINTERFACE;
     }
   }
 
   rv = aStream->Read16(&mCipherSuite);
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
   NS_ENSURE_SUCCESS(rv, rv);
 
   // The code below is a workaround to allow serializing new fields
   // while preserving binary compatibility with older streams. For more details
   // on the binary compatibility requirement, refer to bug 1248628.
   // Here, we take advantage of the fact that mProtocolVersion was originally
   // stored as a 16 bits integer, but the highest 8 bits were never used.
   // These bits are now used for stream versioning.
   uint16_t protocolVersionAndStreamFormatVersion;
   rv = aStream->Read16(&protocolVersionAndStreamFormatVersion);
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
   NS_ENSURE_SUCCESS(rv, rv);
   mProtocolVersion = protocolVersionAndStreamFormatVersion & 0xFF;
   const uint8_t streamFormatVersion =
       (protocolVersionAndStreamFormatVersion >> 8) & 0xFF;
 
   rv = aStream->ReadBoolean(&mIsDomainMismatch);
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
   NS_ENSURE_SUCCESS(rv, rv);
   rv = aStream->ReadBoolean(&mIsNotValidAtThisTime);
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
   NS_ENSURE_SUCCESS(rv, rv);
   rv = aStream->ReadBoolean(&mIsUntrusted);
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
   NS_ENSURE_SUCCESS(rv, rv);
   rv = aStream->ReadBoolean(&mIsEV);
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = aStream->ReadBoolean(&mHasIsEVStatus);
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
   NS_ENSURE_SUCCESS(rv, rv);
   rv = aStream->ReadBoolean(&mHaveCipherSuiteAndProtocol);
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
   NS_ENSURE_SUCCESS(rv, rv);
   rv = aStream->ReadBoolean(&mHaveCertErrorBits);
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Added in version 1 (see bug 1305289).
   if (streamFormatVersion >= 1) {
     rv = aStream->Read16(&mCertificateTransparencyStatus);
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // Added in version 2 (see bug 1304923).
   if (streamFormatVersion >= 2) {
     rv = aStream->ReadCString(mKeaGroup);
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = aStream->ReadCString(mSignatureSchemeName);
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // Added in version 3 (see bug 1406856).
   if (streamFormatVersion >= 3) {
     nsCOMPtr<nsISupports> succeededCertChainSupports;
     rv = NS_ReadOptionalObject(aStream, true,
                                getter_AddRefs(succeededCertChainSupports));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
     if (NS_FAILED(rv)) {
       return rv;
     }
     mSucceededCertChain = do_QueryInterface(succeededCertChainSupports);
 
     // Read only to consume bytes from the stream.
     nsCOMPtr<nsISupports> failedCertChainSupports;
     rv = NS_ReadOptionalObject(aStream, true,
                                getter_AddRefs(failedCertChainSupports));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
     if (NS_FAILED(rv)) {
       return rv;
     }
   }
   return rv;
 }
 
 NS_IMETHODIMP
 TransportSecurityInfo::Read(nsIObjectInputStream* aStream) {
   nsID id;
   nsresult rv = aStream->ReadID(&id);
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
   if (NS_FAILED(rv)) {
     return rv;
   }
   if (!id.Equals(kTransportSecurityInfoMagic)) {
+    MOZ_DIAGNOSTIC_ASSERT(false, "Deserialization should not fail");
     return NS_ERROR_UNEXPECTED;
   }
 
   MutexAutoLock lock(mMutex);
 
   rv = aStream->Read32(&mSecurityState);
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
   if (NS_FAILED(rv)) {
     return rv;
   }
   // mSubRequestsBrokenSecurity was removed in bug 748809
   uint32_t unusedSubRequestsBrokenSecurity;
   rv = aStream->Read32(&unusedSubRequestsBrokenSecurity);
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
   if (NS_FAILED(rv)) {
     return rv;
   }
   // mSubRequestsNoSecurity was removed in bug 748809
   uint32_t unusedSubRequestsNoSecurity;
   rv = aStream->Read32(&unusedSubRequestsNoSecurity);
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
   if (NS_FAILED(rv)) {
     return rv;
   }
   uint32_t errorCode;
   rv = aStream->Read32(&errorCode);
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
   if (NS_FAILED(rv)) {
     return rv;
   }
   // PRErrorCode will be a negative value
   mErrorCode = static_cast<PRErrorCode>(errorCode);
   // If mErrorCode is non-zero, SetCanceled was called on the
   // TransportSecurityInfo that was serialized.
   if (mErrorCode != 0) {
     mCanceled = true;
   }
 
   // Re-purpose mErrorMessageCached to represent serialization version
   // If string doesn't match exact version it will be treated as older
   // serialization.
   nsAutoString serVersion;
   rv = aStream->ReadString(serVersion);
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   // moved from nsISSLStatus
   if (!serVersion.EqualsASCII("1")) {
     // nsISSLStatus may be present
     rv = ReadSSLStatus(aStream);
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
     NS_ENSURE_SUCCESS(rv, rv);
   } else {
     nsCOMPtr<nsISupports> cert;
     rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(cert));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (cert != nullptr) {
       mServerCert = do_QueryInterface(cert);
       if (!mServerCert) {
+        MOZ_DIAGNOSTIC_ASSERT(false,
+                              "Deserialization should not fail");
         return NS_NOINTERFACE;
       }
     }
 
     rv = aStream->Read16(&mCipherSuite);
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = aStream->Read16(&mProtocolVersion);
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = aStream->ReadBoolean(&mIsDomainMismatch);
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
     NS_ENSURE_SUCCESS(rv, rv);
     rv = aStream->ReadBoolean(&mIsNotValidAtThisTime);
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
     NS_ENSURE_SUCCESS(rv, rv);
     rv = aStream->ReadBoolean(&mIsUntrusted);
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
     NS_ENSURE_SUCCESS(rv, rv);
     rv = aStream->ReadBoolean(&mIsEV);
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = aStream->ReadBoolean(&mHasIsEVStatus);
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
     NS_ENSURE_SUCCESS(rv, rv);
     rv = aStream->ReadBoolean(&mHaveCipherSuiteAndProtocol);
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
     NS_ENSURE_SUCCESS(rv, rv);
     rv = aStream->ReadBoolean(&mHaveCertErrorBits);
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = aStream->Read16(&mCertificateTransparencyStatus);
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = aStream->ReadCString(mKeaGroup);
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = aStream->ReadCString(mSignatureSchemeName);
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsISupports> succeededCertChainSupports;
     rv = NS_ReadOptionalObject(aStream, true,
                                getter_AddRefs(succeededCertChainSupports));
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
     if (NS_FAILED(rv)) {
       return rv;
     }
     mSucceededCertChain = do_QueryInterface(succeededCertChainSupports);
   }
   // END moved from nsISSLStatus
 
   nsCOMPtr<nsISupports> failedCertChainSupports;
   rv = NS_ReadOptionalObject(aStream, true,
                              getter_AddRefs(failedCertChainSupports));
+  MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv), "Deserialization should not fail");
   if (NS_FAILED(rv)) {
     return rv;
   }
   mFailedCertChain = do_QueryInterface(failedCertChainSupports);
 
   return NS_OK;
 }