Skip to content

Commit 9827b8a

Browse files
author
tb
committed
Fix leaks in ecx_set_{priv,pub}_key()
When ecx_key_set_{priv,pub}() fails, ecx_key is leaked. CID 377014 From jsing
1 parent 3c31e21 commit 9827b8a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/lib/libcrypto/ec/ecx_methods.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: ecx_methods.c,v 1.2 2022/11/19 07:00:57 tb Exp $ */
1+
/* $OpenBSD: ecx_methods.c,v 1.3 2022/11/23 07:37:06 tb Exp $ */
22
/*
33
* Copyright (c) 2022 Joel Sing <jsing@openbsd.org>
44
*
@@ -511,18 +511,18 @@ ecx_sign_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
511511
static int
512512
ecx_set_priv_key(EVP_PKEY *pkey, const uint8_t *priv, size_t len)
513513
{
514-
struct ecx_key_st *ecx_key;
514+
struct ecx_key_st *ecx_key = NULL;
515515
int ret = 0;
516516

517517
if (priv == NULL || len != ecx_key_len(pkey->ameth->pkey_id)) {
518518
ECerror(EC_R_INVALID_ENCODING);
519-
return 0;
519+
goto err;
520520
}
521521

522522
if ((ecx_key = ecx_key_new(pkey->ameth->pkey_id)) == NULL)
523-
return 0;
523+
goto err;
524524
if (!ecx_key_set_priv(ecx_key, priv, len))
525-
return 0;
525+
goto err;
526526
if (!EVP_PKEY_assign(pkey, pkey->ameth->pkey_id, ecx_key))
527527
goto err;
528528
ecx_key = NULL;
@@ -538,18 +538,18 @@ ecx_set_priv_key(EVP_PKEY *pkey, const uint8_t *priv, size_t len)
538538
static int
539539
ecx_set_pub_key(EVP_PKEY *pkey, const uint8_t *pub, size_t len)
540540
{
541-
struct ecx_key_st *ecx_key;
541+
struct ecx_key_st *ecx_key = NULL;
542542
int ret = 0;
543543

544544
if (pub == NULL || len != ecx_key_len(pkey->ameth->pkey_id)) {
545545
ECerror(EC_R_INVALID_ENCODING);
546-
return 0;
546+
goto err;
547547
}
548548

549549
if ((ecx_key = ecx_key_new(pkey->ameth->pkey_id)) == NULL)
550-
return 0;
550+
goto err;
551551
if (!ecx_key_set_pub(ecx_key, pub, len))
552-
return 0;
552+
goto err;
553553
if (!EVP_PKEY_assign(pkey, pkey->ameth->pkey_id, ecx_key))
554554
goto err;
555555
ecx_key = NULL;

0 commit comments

Comments
 (0)