diff options
| author | tb <> | 2022-11-18 20:03:36 +0000 |
|---|---|---|
| committer | tb <> | 2022-11-18 20:03:36 +0000 |
| commit | 8e2bde89a5d1bb3002c8a910a07e727c01f37646 (patch) | |
| tree | 21a199a413c30508ffcb36f0237841ca9ce7099e /src | |
| parent | 7a0cf2ce1bd281678a901a0cadb489e47b233287 (diff) | |
| download | openbsd-8e2bde89a5d1bb3002c8a910a07e727c01f37646.tar.gz openbsd-8e2bde89a5d1bb3002c8a910a07e727c01f37646.tar.bz2 openbsd-8e2bde89a5d1bb3002c8a910a07e727c01f37646.zip | |
Check os for NULL before dereferencing it
Avoids a segfault when both priv == NULL and os == NULL.
ok miod
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/hmac/hm_ameth.c | 10 |
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) | |||
| 142 | static int | 142 | static int |
| 143 | hmac_get_priv_key(const EVP_PKEY *pkey, unsigned char *priv, size_t *len) | 143 | hmac_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 | } |
