Skip to content

Commit de54ffd

Browse files
author
tb
committed
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
1 parent 93c3743 commit de54ffd

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/lib/libcrypto/ec/ec_asn1.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: ec_asn1.c,v 1.35 2022/01/14 08:16:13 tb Exp $ */
1+
/* $OpenBSD: ec_asn1.c,v 1.36 2022/03/31 13:00:58 tb Exp $ */
22
/*
33
* Written by Nils Larsch for the OpenSSL project.
44
*/
@@ -1285,7 +1285,7 @@ EC_GROUP *
12851285
d2i_ECPKParameters(EC_GROUP ** a, const unsigned char **in, long len)
12861286
{
12871287
EC_GROUP *group = NULL;
1288-
ECPKPARAMETERS *params = NULL;
1288+
ECPKPARAMETERS *params;
12891289

12901290
if ((params = d2i_ECPKPARAMETERS(NULL, in, len)) == NULL) {
12911291
ECerror(EC_R_D2I_ECPKPARAMETERS_FAILURE);
@@ -1332,13 +1332,8 @@ d2i_ECPrivateKey(EC_KEY ** a, const unsigned char **in, long len)
13321332
EC_KEY *ret = NULL;
13331333
EC_PRIVATEKEY *priv_key = NULL;
13341334

1335-
if ((priv_key = EC_PRIVATEKEY_new()) == NULL) {
1336-
ECerror(ERR_R_MALLOC_FAILURE);
1337-
return NULL;
1338-
}
1339-
if ((priv_key = d2i_EC_PRIVATEKEY(&priv_key, in, len)) == NULL) {
1335+
if ((priv_key = d2i_EC_PRIVATEKEY(NULL, in, len)) == NULL) {
13401336
ECerror(ERR_R_EC_LIB);
1341-
EC_PRIVATEKEY_free(priv_key);
13421337
return NULL;
13431338
}
13441339
if (a == NULL || *a == NULL) {

0 commit comments

Comments
 (0)