From 56bbf4102673c77ee6fb342c6a79ef36eddaacf7 Mon Sep 17 00:00:00 2001 From: tb <> Date: Fri, 18 Nov 2022 20:03:36 +0000 Subject: Check os for NULL before dereferencing it Avoids a segfault when both priv == NULL and os == NULL. ok miod --- src/lib/libcrypto/hmac/hm_ameth.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/libcrypto/hmac/hm_ameth.c b/src/lib/libcrypto/hmac/hm_ameth.c index faaa04b461..818fec7d39 100644 --- a/src/lib/libcrypto/hmac/hm_ameth.c +++ b/src/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); } -- cgit v1.2.3-55-g6feb