From 3f640ebd035006d44d6f7d0767bb6ebd1a2efcd5 Mon Sep 17 00:00:00 2001 From: Matt Caswell Date: Tue, 21 Mar 2017 09:53:02 +0000 Subject: [PATCH] Avoid a mem leak on error An internal error path could result in a memory leak. Also remove some redundant code. Reviewed-by: Richard Levitte (Merged from https://github.com/openssl/openssl/pull/3003) --- ssl/s3_srvr.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/ssl/s3_srvr.c b/ssl/s3_srvr.c index 976d6b647c..773358e4ce 100644 --- a/ssl/s3_srvr.c +++ b/ssl/s3_srvr.c @@ -1713,6 +1713,12 @@ int ssl3_send_server_key_exchange(SSL *s) if (type & SSL_kEECDH) { const EC_GROUP *group; + if (s->s3->tmp.ecdh != NULL) { + SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, + ERR_R_INTERNAL_ERROR); + goto err; + } + ecdhp = cert->ecdh_tmp; if (s->cert->ecdh_tmp_auto) { /* Get NID of appropriate shared curve */ @@ -1733,17 +1739,7 @@ int ssl3_send_server_key_exchange(SSL *s) goto f_err; } - if (s->s3->tmp.ecdh != NULL) { - SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, - ERR_R_INTERNAL_ERROR); - goto err; - } - /* Duplicate the ECDH structure. */ - if (ecdhp == NULL) { - SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE, ERR_R_ECDH_LIB); - goto err; - } if (s->cert->ecdh_tmp_auto) ecdh = ecdhp; else if ((ecdh = EC_KEY_dup(ecdhp)) == NULL) { -- 2.40.0