summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2023-12-28 22:00:56 +0000
committertb <>2023-12-28 22:00:56 +0000
commitda696300181170af441e4635858fb24e8a6273f3 (patch)
tree8f8dfe383b017bc6508e862b3e6ae487a7e0d041
parente204ca5b61f4c88fa4e9bf36f0b6b0603bb99e1d (diff)
downloadopenbsd-da696300181170af441e4635858fb24e8a6273f3.tar.gz
openbsd-da696300181170af441e4635858fb24e8a6273f3.tar.bz2
openbsd-da696300181170af441e4635858fb24e8a6273f3.zip
Rework and fix pkey_hmac_keygen()
The usual: single exit, error check all functions even if they can't actually fail. This one was flagged again. ok jsing CID 471706 (false positive)
-rw-r--r--src/lib/libcrypto/hmac/hm_pmeth.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/lib/libcrypto/hmac/hm_pmeth.c b/src/lib/libcrypto/hmac/hm_pmeth.c
index 5ec86aa095..05eb1bf85d 100644
--- a/src/lib/libcrypto/hmac/hm_pmeth.c
+++ b/src/lib/libcrypto/hmac/hm_pmeth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: hm_pmeth.c,v 1.16 2023/11/29 21:35:57 tb Exp $ */ 1/* $OpenBSD: hm_pmeth.c,v 1.17 2023/12/28 22:00:56 tb Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2007. 3 * project 2007.
4 */ 4 */
@@ -131,15 +131,22 @@ pkey_hmac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
131{ 131{
132 ASN1_OCTET_STRING *hkey = NULL; 132 ASN1_OCTET_STRING *hkey = NULL;
133 HMAC_PKEY_CTX *hctx = ctx->data; 133 HMAC_PKEY_CTX *hctx = ctx->data;
134 int ret = 0;
134 135
135 if (!hctx->ktmp.data) 136 if (hctx->ktmp.data == NULL)
136 return 0; 137 goto err;
137 hkey = ASN1_OCTET_STRING_dup(&hctx->ktmp); 138 if ((hkey = ASN1_OCTET_STRING_dup(&hctx->ktmp)) == NULL)
138 if (!hkey) 139 goto err;
139 return 0; 140 if (!EVP_PKEY_assign(pkey, EVP_PKEY_HMAC, hkey))
140 EVP_PKEY_assign(pkey, EVP_PKEY_HMAC, hkey); 141 goto err;
142 hkey = NULL;
141 143
142 return 1; 144 ret = 1;
145
146 err:
147 ASN1_OCTET_STRING_free(hkey);
148
149 return ret;
143} 150}
144 151
145static int 152static int