summaryrefslogtreecommitdiffstats
path: root/crypto/x509/x_pubkey.c
diff options
context:
space:
mode:
authorPauli <pauli@openssl.org>2021-06-25 12:54:43 +1000
committerPauli <pauli@openssl.org>2021-06-26 11:33:52 +1000
commit150251904c2b4c2cffd7429af90cd0486e3682d7 (patch)
tree22a146eccaecf3c3975903a52dbbad5b18590338 /crypto/x509/x_pubkey.c
parentd4af922c583ce152f7d8f35869ab92d5b37cbfd2 (diff)
x509: address NULL dereference and memory leaks
Reviewed-by: Shane Lontis <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/15910)
Diffstat (limited to 'crypto/x509/x_pubkey.c')
-rw-r--r--crypto/x509/x_pubkey.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/crypto/x509/x_pubkey.c b/crypto/x509/x_pubkey.c
index e669ae3574..b20b756e9a 100644
--- a/crypto/x509/x_pubkey.c
+++ b/crypto/x509/x_pubkey.c
@@ -84,14 +84,16 @@ void ossl_X509_PUBKEY_INTERNAL_free(X509_PUBKEY *xpub)
static void x509_pubkey_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
{
- X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval;
+ X509_PUBKEY *pubkey;
- X509_ALGOR_free(pubkey->algor);
- ASN1_BIT_STRING_free(pubkey->public_key);
- EVP_PKEY_free(pubkey->pkey);
- OPENSSL_free(pubkey->propq);
- OPENSSL_free(pubkey);
- *pval = NULL;
+ if (pval != NULL && (pubkey = (X509_PUBKEY *)*pval) != NULL) {
+ X509_ALGOR_free(pubkey->algor);
+ ASN1_BIT_STRING_free(pubkey->public_key);
+ EVP_PKEY_free(pubkey->pkey);
+ OPENSSL_free(pubkey->propq);
+ OPENSSL_free(pubkey);
+ *pval = NULL;
+ }
}
static int x509_pubkey_ex_populate(ASN1_VALUE **pval, const ASN1_ITEM *it)