From: tb Date: Thu, 31 Mar 2022 13:00:58 +0000 (+0000) Subject: Simplify priv_key handling in d2i_ECPrivateKey() X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=cabe998964bbae1a09f89296e742a018387bf5b0;p=openbsd 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 --- diff --git a/lib/libcrypto/ec/ec_asn1.c b/lib/libcrypto/ec/ec_asn1.c index 6ec8ab08743..4cf0bf59726 100644 --- a/lib/libcrypto/ec/ec_asn1.c +++ b/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) {