diff options
author | tobhe <> | 2022-11-08 12:59:36 +0000 |
---|---|---|
committer | tobhe <> | 2022-11-08 12:59:36 +0000 |
commit | bfb1b5d6f477a9190226a52894ee85e3a87fa09a (patch) | |
tree | 0045b4112408a8f22b04858bf5a98fadc7e5ed09 | |
parent | 1b638f6021d5c11fb59141323a36e2cd02da5f36 (diff) | |
download | openbsd-bfb1b5d6f477a9190226a52894ee85e3a87fa09a.tar.gz openbsd-bfb1b5d6f477a9190226a52894ee85e3a87fa09a.tar.bz2 openbsd-bfb1b5d6f477a9190226a52894ee85e3a87fa09a.zip |
Fix leak of pk if EVP_PKEY_set1_RSA() fails.
Found with CodeChecker
feedback and ok tb@
-rw-r--r-- | src/lib/libcrypto/rsa/rsa_prn.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_prn.c b/src/lib/libcrypto/rsa/rsa_prn.c index c46b08c00d..46e09dc117 100644 --- a/src/lib/libcrypto/rsa/rsa_prn.c +++ b/src/lib/libcrypto/rsa/rsa_prn.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rsa_prn.c,v 1.7 2017/01/29 17:49:23 beck Exp $ */ | 1 | /* $OpenBSD: rsa_prn.c,v 1.8 2022/11/08 12:59:36 tobhe Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2006. | 3 | * project 2006. |
4 | */ | 4 | */ |
@@ -82,12 +82,16 @@ int | |||
82 | RSA_print(BIO *bp, const RSA *x, int off) | 82 | RSA_print(BIO *bp, const RSA *x, int off) |
83 | { | 83 | { |
84 | EVP_PKEY *pk; | 84 | EVP_PKEY *pk; |
85 | int ret; | 85 | int ret = 0; |
86 | |||
87 | if ((pk = EVP_PKEY_new()) == NULL) | ||
88 | goto out; | ||
89 | |||
90 | if (!EVP_PKEY_set1_RSA(pk, (RSA *)x)) | ||
91 | goto out; | ||
86 | 92 | ||
87 | pk = EVP_PKEY_new(); | ||
88 | if (!pk || !EVP_PKEY_set1_RSA(pk, (RSA *)x)) | ||
89 | return 0; | ||
90 | ret = EVP_PKEY_print_private(bp, pk, off, NULL); | 93 | ret = EVP_PKEY_print_private(bp, pk, off, NULL); |
94 | out: | ||
91 | EVP_PKEY_free(pk); | 95 | EVP_PKEY_free(pk); |
92 | return ret; | 96 | return ret; |
93 | } | 97 | } |