From f3eb1438202f5e8cde8e5d91db8039f16d142529 Mon Sep 17 00:00:00 2001 From: tobhe Date: Thu, 10 Nov 2022 12:37:00 +0000 Subject: [PATCH] Fix a few more leaks in *_print() functions. ok jsing@ --- lib/libcrypto/dsa/dsa_prn.c | 14 +++++++++----- lib/libcrypto/ec/eck_prn.c | 28 +++++++++++++++++++--------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/lib/libcrypto/dsa/dsa_prn.c b/lib/libcrypto/dsa/dsa_prn.c index a26f3cfc6a3..a2063283eaa 100644 --- a/lib/libcrypto/dsa/dsa_prn.c +++ b/lib/libcrypto/dsa/dsa_prn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsa_prn.c,v 1.7 2022/11/08 19:17:05 tobhe Exp $ */ +/* $OpenBSD: dsa_prn.c,v 1.8 2022/11/10 12:37:00 tobhe Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -116,12 +116,16 @@ int DSAparams_print(BIO *bp, const DSA *x) { EVP_PKEY *pk; - int ret; + int ret = 0; + + if ((pk = EVP_PKEY_new()) == NULL) + goto err; + + if (!EVP_PKEY_set1_DSA(pk, (DSA *)x)) + goto err; - pk = EVP_PKEY_new(); - if (!pk || !EVP_PKEY_set1_DSA(pk, (DSA *)x)) - return 0; ret = EVP_PKEY_print_params(bp, pk, 4, NULL); + err: EVP_PKEY_free(pk); return ret; } diff --git a/lib/libcrypto/ec/eck_prn.c b/lib/libcrypto/ec/eck_prn.c index c2fd2ebc85b..058ae57de5b 100644 --- a/lib/libcrypto/ec/eck_prn.c +++ b/lib/libcrypto/ec/eck_prn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eck_prn.c,v 1.17 2021/04/20 17:12:43 tb Exp $ */ +/* $OpenBSD: eck_prn.c,v 1.18 2022/11/10 12:37:00 tobhe Exp $ */ /* * Written by Nils Larsch for the OpenSSL project. */ @@ -121,11 +121,16 @@ int EC_KEY_print(BIO * bp, const EC_KEY * x, int off) { EVP_PKEY *pk; - int ret; - pk = EVP_PKEY_new(); - if (!pk || !EVP_PKEY_set1_EC_KEY(pk, (EC_KEY *) x)) - return 0; + int ret = 0; + + if ((pk = EVP_PKEY_new()) == NULL) + goto err; + + if (!EVP_PKEY_set1_EC_KEY(pk, (EC_KEY *) x)) + goto err; + ret = EVP_PKEY_print_private(bp, pk, off, NULL); + err: EVP_PKEY_free(pk); return ret; } @@ -134,11 +139,16 @@ int ECParameters_print(BIO * bp, const EC_KEY * x) { EVP_PKEY *pk; - int ret; - pk = EVP_PKEY_new(); - if (!pk || !EVP_PKEY_set1_EC_KEY(pk, (EC_KEY *) x)) - return 0; + int ret = 0; + + if ((pk = EVP_PKEY_new()) == NULL) + goto err; + + if (!EVP_PKEY_set1_EC_KEY(pk, (EC_KEY *) x)) + goto err; + ret = EVP_PKEY_print_params(bp, pk, 4, NULL); + err: EVP_PKEY_free(pk); return ret; } -- 2.20.1