summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2022-11-18 20:03:36 +0000
committertb <>2022-11-18 20:03:36 +0000
commit56bbf4102673c77ee6fb342c6a79ef36eddaacf7 (patch)
tree21a199a413c30508ffcb36f0237841ca9ce7099e
parent9c7e421fa26bb5dcca9cf2ae11ed37a6b592bc44 (diff)
downloadopenbsd-56bbf4102673c77ee6fb342c6a79ef36eddaacf7.tar.gz
openbsd-56bbf4102673c77ee6fb342c6a79ef36eddaacf7.tar.bz2
openbsd-56bbf4102673c77ee6fb342c6a79ef36eddaacf7.zip
Check os for NULL before dereferencing it
Avoids a segfault when both priv == NULL and os == NULL. ok miod
-rw-r--r--src/lib/libcrypto/hmac/hm_ameth.c10
1 files 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 @@
1/* $OpenBSD: hm_ameth.c,v 1.15 2022/11/18 15:10:51 tb Exp $ */ 1/* $OpenBSD: hm_ameth.c,v 1.16 2022/11/18 20:03:36 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 */
@@ -142,17 +142,17 @@ hmac_set_priv_key(EVP_PKEY *pkey, const unsigned char *priv, size_t len)
142static int 142static int
143hmac_get_priv_key(const EVP_PKEY *pkey, unsigned char *priv, size_t *len) 143hmac_get_priv_key(const EVP_PKEY *pkey, unsigned char *priv, size_t *len)
144{ 144{
145 ASN1_OCTET_STRING *os = pkey->pkey.ptr; 145 ASN1_OCTET_STRING *os;
146 CBS cbs; 146 CBS cbs;
147 147
148 if ((os = pkey->pkey.ptr) == NULL)
149 return 0;
150
148 if (priv == NULL) { 151 if (priv == NULL) {
149 *len = os->length; 152 *len = os->length;
150 return 1; 153 return 1;
151 } 154 }
152 155
153 if (os == NULL)
154 return 0;
155
156 CBS_init(&cbs, os->data, os->length); 156 CBS_init(&cbs, os->data, os->length);
157 return CBS_write_bytes(&cbs, priv, *len, len); 157 return CBS_write_bytes(&cbs, priv, *len, len);
158} 158}