Bug 1034856 - Follow-up to fix small SECItem leak in PublicKeyToSpki() on a CLOSED TREE r=bustage
authorTim Taubert <ttaubert@mozilla.com>
Fri, 17 Oct 2014 15:14:18 +0200
changeset 211032 cc77c762d6a0c1d167f05e136c9c792d37995572
parent 211031 3c6233f10333bb25a5b4fc115eded2ed10010964
child 211033 6e17d46ddda46d459e04478e8a840fe876cdd2da
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersbustage
bugs1034856
milestone36.0a1
Bug 1034856 - Follow-up to fix small SECItem leak in PublicKeyToSpki() on a CLOSED TREE r=bustage
dom/crypto/CryptoKey.cpp
--- a/dom/crypto/CryptoKey.cpp
+++ b/dom/crypto/CryptoKey.cpp
@@ -458,37 +458,36 @@ CryptoKey::PrivateKeyToPkcs8(SECKEYPriva
     return NS_ERROR_DOM_INVALID_ACCESS_ERR;
   }
   aRetVal.Assign(pkcs8Item.get());
   return NS_OK;
 }
 
 nsresult
 PublicDhKeyToSpki(SECKEYPublicKey* aPubKey,
-                  CERTSubjectPublicKeyInfo* aSpki,
-                  PLArenaPool* aArena)
+                  CERTSubjectPublicKeyInfo* aSpki)
 {
-  SECItem* params = ::SECITEM_AllocItem(aArena, nullptr, 0);
+  SECItem* params = ::SECITEM_AllocItem(aSpki->arena, nullptr, 0);
   if (!params) {
     return NS_ERROR_DOM_OPERATION_ERR;
   }
 
-  SECItem* rvItem = SEC_ASN1EncodeItem(aArena, params, aPubKey,
+  SECItem* rvItem = SEC_ASN1EncodeItem(aSpki->arena, params, aPubKey,
                                        SECKEY_DHParamKeyTemplate);
   if (!rvItem) {
     return NS_ERROR_DOM_OPERATION_ERR;
   }
 
-  SECStatus rv = SECOID_SetAlgorithmID(aArena, &aSpki->algorithm,
+  SECStatus rv = SECOID_SetAlgorithmID(aSpki->arena, &aSpki->algorithm,
                                        SEC_OID_X942_DIFFIE_HELMAN_KEY, params);
   if (rv != SECSuccess) {
     return NS_ERROR_DOM_OPERATION_ERR;
   }
 
-  rvItem = SEC_ASN1EncodeItem(aArena, &aSpki->subjectPublicKey, aPubKey,
+  rvItem = SEC_ASN1EncodeItem(aSpki->arena, &aSpki->subjectPublicKey, aPubKey,
                               SECKEY_DHPublicKeyTemplate);
   if (!rvItem) {
     return NS_ERROR_DOM_OPERATION_ERR;
   }
 
   // The public value is a BIT_STRING encoded as an INTEGER. After encoding
   // an INT we need to adjust the length to reflect the number of bits.
   aSpki->subjectPublicKey.len <<= 3;
@@ -517,17 +516,17 @@ CryptoKey::PublicKeyToSpki(SECKEYPublicK
       return NS_ERROR_DOM_OPERATION_ERR;
     }
 
     // Assign |arena| to |spki| and null the variable afterwards so that the
     // arena created above that holds the SPKI object is free'd when |spki|
     // goes out of scope, not when |arena| does.
     spki->arena = arena.forget();
 
-    nsresult rv = PublicDhKeyToSpki(aPubKey, spki, arena);
+    nsresult rv = PublicDhKeyToSpki(aPubKey, spki);
     NS_ENSURE_SUCCESS(rv, rv);
   } else {
     spki = SECKEY_CreateSubjectPublicKeyInfo(aPubKey);
     if (!spki) {
       return NS_ERROR_DOM_OPERATION_ERR;
     }
   }