diff options
author | Theo Buehler <tb@cvs.openbsd.org> | 2022-11-23 07:37:07 +0000 |
---|---|---|
committer | Theo Buehler <tb@cvs.openbsd.org> | 2022-11-23 07:37:07 +0000 |
commit | 3d300cb6921d6ba84460c9c193e9ddecbdbcae95 (patch) | |
tree | 25a678aa52bb30d7467a97ecb8542323535b621d | |
parent | bd9c5ed8c6cd63f6071deb70d9cb88c1242d1ecf (diff) |
Fix leaks in ecx_set_{priv,pub}_key()
When ecx_key_set_{priv,pub}() fails, ecx_key is leaked.
CID 377014
From jsing
-rw-r--r-- | lib/libcrypto/ec/ecx_methods.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/libcrypto/ec/ecx_methods.c b/lib/libcrypto/ec/ecx_methods.c index 8829d8fdbc9..4de7f1565ee 100644 --- a/lib/libcrypto/ec/ecx_methods.c +++ b/lib/libcrypto/ec/ecx_methods.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ecx_methods.c,v 1.2 2022/11/19 07:00:57 tb Exp $ */ +/* $OpenBSD: ecx_methods.c,v 1.3 2022/11/23 07:37:06 tb Exp $ */ /* * Copyright (c) 2022 Joel Sing <jsing@openbsd.org> * @@ -511,18 +511,18 @@ ecx_sign_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2) static int ecx_set_priv_key(EVP_PKEY *pkey, const uint8_t *priv, size_t len) { - struct ecx_key_st *ecx_key; + struct ecx_key_st *ecx_key = NULL; int ret = 0; if (priv == NULL || len != ecx_key_len(pkey->ameth->pkey_id)) { ECerror(EC_R_INVALID_ENCODING); - return 0; + goto err; } if ((ecx_key = ecx_key_new(pkey->ameth->pkey_id)) == NULL) - return 0; + goto err; if (!ecx_key_set_priv(ecx_key, priv, len)) - return 0; + goto err; if (!EVP_PKEY_assign(pkey, pkey->ameth->pkey_id, ecx_key)) goto err; ecx_key = NULL; @@ -538,18 +538,18 @@ ecx_set_priv_key(EVP_PKEY *pkey, const uint8_t *priv, size_t len) static int ecx_set_pub_key(EVP_PKEY *pkey, const uint8_t *pub, size_t len) { - struct ecx_key_st *ecx_key; + struct ecx_key_st *ecx_key = NULL; int ret = 0; if (pub == NULL || len != ecx_key_len(pkey->ameth->pkey_id)) { ECerror(EC_R_INVALID_ENCODING); - return 0; + goto err; } if ((ecx_key = ecx_key_new(pkey->ameth->pkey_id)) == NULL) - return 0; + goto err; if (!ecx_key_set_pub(ecx_key, pub, len)) - return 0; + goto err; if (!EVP_PKEY_assign(pkey, pkey->ameth->pkey_id, ecx_key)) goto err; ecx_key = NULL; |