Fix X509_PUBKEY_dup() to not leak memory
@@ -207,10 +207,9 @@ IMPLEMENT_ASN1_FUNCTIONS(X509_PUBKEY)
*/
X509_PUBKEY *X509_PUBKEY_dup(const X509_PUBKEY *a)
{
- X509_PUBKEY *pubkey = NULL;
+ X509_PUBKEY *pubkey = OPENSSL_zalloc(sizeof(*pubkey));
- if (!x509_pubkey_ex_new((ASN1_VALUE **)&pubkey,
- ASN1_ITEM_rptr(X509_PUBKEY_INTERNAL))
+ if (pubkey == NULL
|| !x509_pubkey_set0_libctx(pubkey, a->libctx, a->propq)
|| (pubkey->algor = X509_ALGOR_dup(a->algor)) == NULL
|| (pubkey->public_key = ASN1_BIT_STRING_new()) == NULL
@@ -222,7 +221,6 @@ X509_PUBKEY *X509_PUBKEY_dup(const X509_PUBKEY *a)
ERR_raise(ERR_LIB_X509, ERR_R_MALLOC_FAILURE);
return NULL;
}
-
pubkey->pkey = a->pkey;
return pubkey;
}
