Skip to content

Commit 0b62cfa

Browse files
author
tb
committed
Avoid segfaults in EVP_PKEY_CTX_free()
It is possible to call pmeth->cleanup() with an EVP_PKEY_CTX whose data is NULL. If pmeth->init() in int_ctx_new() fails, EVP_PKEY_CTX_free() is called with such a context. This in turn calls pmeth->cleanup(), and thus these cleanup functions must be careful not to use NULL data. Most of them are, but one of GOST's functions and HMAC's aren't. Reported for HMAC by Masaru Masada #129 ok bcook jsing
1 parent a7b96f3 commit 0b62cfa

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/lib/libcrypto/gost/gostr341001_pmeth.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: gostr341001_pmeth.c,v 1.15 2022/01/07 09:40:03 tb Exp $ */
1+
/* $OpenBSD: gostr341001_pmeth.c,v 1.16 2022/03/30 07:17:48 tb Exp $ */
22
/*
33
* Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
44
* Copyright (c) 2005-2006 Cryptocom LTD
@@ -175,7 +175,10 @@ pkey_gost01_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
175175
static void
176176
pkey_gost01_cleanup(EVP_PKEY_CTX *ctx)
177177
{
178-
struct gost_pmeth_data *data = EVP_PKEY_CTX_get_data(ctx);
178+
struct gost_pmeth_data *data;
179+
180+
if ((data = EVP_PKEY_CTX_get_data(ctx)) == NULL)
181+
return;
179182

180183
free(data->shared_ukm);
181184
free(data);

src/lib/libcrypto/hmac/hm_pmeth.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: hm_pmeth.c,v 1.12 2022/03/30 07:12:30 tb Exp $ */
1+
/* $OpenBSD: hm_pmeth.c,v 1.13 2022/03/30 07:17:48 tb Exp $ */
22
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
33
* project 2007.
44
*/
@@ -116,7 +116,10 @@ pkey_hmac_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
116116
static void
117117
pkey_hmac_cleanup(EVP_PKEY_CTX *ctx)
118118
{
119-
HMAC_PKEY_CTX *hctx = ctx->data;
119+
HMAC_PKEY_CTX *hctx;
120+
121+
if ((hctx = ctx->data) == NULL)
122+
return;
120123

121124
HMAC_CTX_cleanup(&hctx->ctx);
122125
freezero(hctx->ktmp.data, hctx->ktmp.length);

0 commit comments

Comments
 (0)