From 91087446015ebb4341a9f7c6accff0e586a0ba5d Mon Sep 17 00:00:00 2001 From: tb <> Date: Thu, 31 Mar 2022 13:00:58 +0000 Subject: Simplify priv_key handling in d2i_ECPrivateKey() d2i_EC_PRIVATEKEY() can handle the allocation of priv_key internally, no need to do this up front and reach it through the dangerous reuse mechanism. There's also no point in freeing a variable we know to be NULL. ok jsing --- src/lib/libcrypto/ec/ec_asn1.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'src/lib') diff --git a/src/lib/libcrypto/ec/ec_asn1.c b/src/lib/libcrypto/ec/ec_asn1.c index 6ec8ab0874..4cf0bf5972 100644 --- a/src/lib/libcrypto/ec/ec_asn1.c +++ b/src/lib/libcrypto/ec/ec_asn1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ec_asn1.c,v 1.35 2022/01/14 08:16:13 tb Exp $ */ +/* $OpenBSD: ec_asn1.c,v 1.36 2022/03/31 13:00:58 tb Exp $ */ /* * Written by Nils Larsch for the OpenSSL project. */ @@ -1285,7 +1285,7 @@ EC_GROUP * d2i_ECPKParameters(EC_GROUP ** a, const unsigned char **in, long len) { EC_GROUP *group = NULL; - ECPKPARAMETERS *params = NULL; + ECPKPARAMETERS *params; if ((params = d2i_ECPKPARAMETERS(NULL, in, len)) == NULL) { ECerror(EC_R_D2I_ECPKPARAMETERS_FAILURE); @@ -1332,13 +1332,8 @@ d2i_ECPrivateKey(EC_KEY ** a, const unsigned char **in, long len) EC_KEY *ret = NULL; EC_PRIVATEKEY *priv_key = NULL; - if ((priv_key = EC_PRIVATEKEY_new()) == NULL) { - ECerror(ERR_R_MALLOC_FAILURE); - return NULL; - } - if ((priv_key = d2i_EC_PRIVATEKEY(&priv_key, in, len)) == NULL) { + if ((priv_key = d2i_EC_PRIVATEKEY(NULL, in, len)) == NULL) { ECerror(ERR_R_EC_LIB); - EC_PRIVATEKEY_free(priv_key); return NULL; } if (a == NULL || *a == NULL) { -- cgit v1.2.3-55-g6feb