From ff448807c2a56143d75f46091941ee8f94d2fd73 Mon Sep 17 00:00:00 2001 From: tb Date: Fri, 18 Nov 2022 20:03:36 +0000 Subject: [PATCH] Check os for NULL before dereferencing it Avoids a segfault when both priv == NULL and os == NULL. ok miod --- lib/libcrypto/hmac/hm_ameth.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/libcrypto/hmac/hm_ameth.c b/lib/libcrypto/hmac/hm_ameth.c index faaa04b461b..818fec7d392 100644 --- a/lib/libcrypto/hmac/hm_ameth.c +++ b/lib/libcrypto/hmac/hm_ameth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hm_ameth.c,v 1.15 2022/11/18 15:10:51 tb Exp $ */ +/* $OpenBSD: hm_ameth.c,v 1.16 2022/11/18 20:03:36 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2007. */ @@ -142,17 +142,17 @@ hmac_set_priv_key(EVP_PKEY *pkey, const unsigned char *priv, size_t len) static int hmac_get_priv_key(const EVP_PKEY *pkey, unsigned char *priv, size_t *len) { - ASN1_OCTET_STRING *os = pkey->pkey.ptr; + ASN1_OCTET_STRING *os; CBS cbs; + if ((os = pkey->pkey.ptr) == NULL) + return 0; + if (priv == NULL) { *len = os->length; return 1; } - if (os == NULL) - return 0; - CBS_init(&cbs, os->data, os->length); return CBS_write_bytes(&cbs, priv, *len, len); } -- 2.20.1