Bug 399706, glibc detected: free(): invalid pointer attempting to select cert Landing better patch. r=rrelyea, a/blocking=beltzner
authorkaie@kuix.de
Fri, 09 Nov 2007 07:09:58 -0800
changeset 7744 5b2cc2b195231c00105949419afdc36d6f59f112
parent 7743 d2c7bdea86178263cc12b481fc37ed137c3ed471
child 7745 5b362c858fd171ee1041c14096a45344640a9302
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrrelyea, a
bugs399706
milestone1.9b2pre
Bug 399706, glibc detected: free(): invalid pointer attempting to select cert Landing better patch. r=rrelyea, a/blocking=beltzner
security/manager/ssl/src/nsNSSCertificate.cpp
--- a/security/manager/ssl/src/nsNSSCertificate.cpp
+++ b/security/manager/ssl/src/nsNSSCertificate.cpp
@@ -451,54 +451,57 @@ nsNSSCertificate::FormatUIStrings(const 
       if (NS_SUCCEEDED(nssComponent->GetPIPNSSBundleString("CertDumpKeyUsage", info))) {
         details.Append(info);
         details.AppendLiteral(": ");
       }
       details.Append(temp1);
       details.Append(PRUnichar('\n'));
     }
 
-    PRUint32 num;
-    PRUnichar **emailArray = NULL;
-    if (NS_SUCCEEDED(GetEmailAddresses(&num, &emailArray)) && num > 0) {
-      PRUnichar **emailAddr = emailArray;
-      details.AppendLiteral("  ");
-      if (NS_SUCCEEDED(nssComponent->GetPIPNSSBundleString("CertInfoEmail", info))) {
-        details.Append(info);
-        details.AppendLiteral(": ");
-      }
-      details.Append(*emailAddr);
+    nsAutoString firstEmail;
+    const char *aWalkAddr;
+    for (aWalkAddr = CERT_GetFirstEmailAddress(mCert)
+         ;
+         aWalkAddr
+         ;
+         aWalkAddr = CERT_GetNextEmailAddress(mCert, aWalkAddr))
+    {
+      NS_ConvertUTF8toUTF16 email(aWalkAddr);
+      if (email.IsEmpty())
+        continue;
+
+      if (firstEmail.IsEmpty()) {
+        /*
+         * If the first email address from the subject DN is also present
+         * in the subjectAltName extension, GetEmailAddresses() will return
+         * it twice (as received from NSS). Remember the first address so that
+         * we can filter out duplicates later on.
+         */
+        firstEmail = email;
 
-      /*
-       * If the first email address from the subject DN is also present
-       * in the subjectAltName extension, GetEmailAddresses() will return
-       * it twice (as received from NSS). Remember the first address so that
-       * we can filter out duplicates later on.
-       */
-      PRUnichar *firstEmail = *emailAddr;
-      emailAddr++;
-      num--;
-
-      /* append remaining addresses */
-      while (num > 0) {
-        if (!nsDependentString(firstEmail).Equals(nsDependentString(*emailAddr))) {
+        details.AppendLiteral("  ");
+        if (NS_SUCCEEDED(nssComponent->GetPIPNSSBundleString("CertInfoEmail", info))) {
+          details.Append(info);
+          details.AppendLiteral(": ");
+        }
+        details.Append(email);
+      }
+      else {
+        // Append current address if it's different from the first one.
+        if (!firstEmail.Equals(email)) {
           details.AppendLiteral(", ");
-          details.Append(*emailAddr);
+          details.Append(email);
         }
-        nsMemory::Free(*emailAddr);
-        *emailAddr = nsnull;
-        emailAddr++;
-        num--;
       }
+    }
 
+    if (!firstEmail.IsEmpty()) {
+      // We got at least one email address, so we want a newline
       details.Append(PRUnichar('\n'));
-      nsMemory::Free(firstEmail);
     }
-    nsMemory::Free(emailArray);
-    emailArray = nsnull;
 
     if (NS_SUCCEEDED(nssComponent->GetPIPNSSBundleString("CertInfoIssuedBy", info))) {
       details.Append(info);
       details.Append(PRUnichar(' '));
 
       if (NS_SUCCEEDED(x509Proxy->GetIssuerName(temp1)) && !temp1.IsEmpty()) {
         details.Append(temp1);
       }