diff options
author | Tomas Mraz <tomas@openssl.org> | 2021-07-21 18:45:01 +0200 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2021-07-23 09:06:18 +0200 |
commit | 40184c96103a388209939c1c19920971c05bb78c (patch) | |
tree | 00b7047410a88afc8a67375d2a46a9fa0c955de1 | |
parent | Add a test for custom EVP_PKEY_METHODs (diff) | |
download | openssl-40184c96103a388209939c1c19920971c05bb78c.tar.xz openssl-40184c96103a388209939c1c19920971c05bb78c.zip |
DSA/RSA_print(): Fix potential memory leak
Fixes #10777
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/16130)
-rw-r--r-- | crypto/dsa/dsa_prn.c | 12 | ||||
-rw-r--r-- | crypto/rsa/rsa_prn.c | 6 |
2 files changed, 12 insertions, 6 deletions
diff --git a/crypto/dsa/dsa_prn.c b/crypto/dsa/dsa_prn.c index c5ec7d5dfe..6f001a50f0 100644 --- a/crypto/dsa/dsa_prn.c +++ b/crypto/dsa/dsa_prn.c @@ -55,9 +55,11 @@ int DSA_print(BIO *bp, const DSA *x, int off) EVP_PKEY *pk; int ret; pk = EVP_PKEY_new(); - if (pk == NULL || !EVP_PKEY_set1_DSA(pk, (DSA *)x)) + if (pk == NULL) return 0; - ret = EVP_PKEY_print_private(bp, pk, off, NULL); + ret = EVP_PKEY_set1_DSA(pk, (DSA *)x); + if (ret) + ret = EVP_PKEY_print_private(bp, pk, off, NULL); EVP_PKEY_free(pk); return ret; } @@ -67,9 +69,11 @@ int DSAparams_print(BIO *bp, const DSA *x) EVP_PKEY *pk; int ret; pk = EVP_PKEY_new(); - if (pk == NULL || !EVP_PKEY_set1_DSA(pk, (DSA *)x)) + if (pk == NULL) return 0; - ret = EVP_PKEY_print_params(bp, pk, 4, NULL); + ret = EVP_PKEY_set1_DSA(pk, (DSA *)x); + if (ret) + ret = EVP_PKEY_print_params(bp, pk, 4, NULL); EVP_PKEY_free(pk); return ret; } diff --git a/crypto/rsa/rsa_prn.c b/crypto/rsa/rsa_prn.c index 4a317dadc4..35723c87ae 100644 --- a/crypto/rsa/rsa_prn.c +++ b/crypto/rsa/rsa_prn.c @@ -40,9 +40,11 @@ int RSA_print(BIO *bp, const RSA *x, int off) EVP_PKEY *pk; int ret; pk = EVP_PKEY_new(); - if (pk == NULL || !EVP_PKEY_set1_RSA(pk, (RSA *)x)) + if (pk == NULL) return 0; - ret = EVP_PKEY_print_private(bp, pk, off, NULL); + ret = EVP_PKEY_set1_RSA(pk, (RSA *)x); + if (ret) + ret = EVP_PKEY_print_private(bp, pk, off, NULL); EVP_PKEY_free(pk); return ret; } |