diff options
| author | tb <> | 2023-06-15 13:22:25 +0000 |
|---|---|---|
| committer | tb <> | 2023-06-15 13:22:25 +0000 |
| commit | 32dcf34689ac9d8dcc1aa58cbe0d9306c5798e64 (patch) | |
| tree | 677727a539f5645b9609751d4dc56d2402688048 /src | |
| parent | 47313acca923490fcdfade8b3199296f7d1055cf (diff) | |
| download | openbsd-32dcf34689ac9d8dcc1aa58cbe0d9306c5798e64.tar.gz openbsd-32dcf34689ac9d8dcc1aa58cbe0d9306c5798e64.tar.bz2 openbsd-32dcf34689ac9d8dcc1aa58cbe0d9306c5798e64.zip | |
Make NULL checks explicit in ASN1_item_sign_ctx()
Also move the NULL check for the EVP_MD into the rv == 2 path, which
is the only branch where it is used.
ok jsing
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/asn1/asn1_item.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_item.c b/src/lib/libcrypto/asn1/asn1_item.c index 10b6780590..6efe7314e7 100644 --- a/src/lib/libcrypto/asn1/asn1_item.c +++ b/src/lib/libcrypto/asn1/asn1_item.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: asn1_item.c,v 1.9 2023/06/15 13:07:45 tb Exp $ */ | 1 | /* $OpenBSD: asn1_item.c,v 1.10 2023/06/15 13:22:25 tb Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -240,10 +240,7 @@ ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, | |||
| 240 | int rv = 2; | 240 | int rv = 2; |
| 241 | int ret = 0; | 241 | int ret = 0; |
| 242 | 242 | ||
| 243 | type = EVP_MD_CTX_md(ctx); | 243 | if ((pkey = EVP_PKEY_CTX_get0_pkey(ctx->pctx)) == NULL) { |
| 244 | pkey = EVP_PKEY_CTX_get0_pkey(ctx->pctx); | ||
| 245 | |||
| 246 | if (!type || !pkey) { | ||
| 247 | ASN1error(ASN1_R_CONTEXT_NOT_INITIALISED); | 244 | ASN1error(ASN1_R_CONTEXT_NOT_INITIALISED); |
| 248 | return 0; | 245 | return 0; |
| 249 | } | 246 | } |
| @@ -253,7 +250,7 @@ ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, | |||
| 253 | return 0; | 250 | return 0; |
| 254 | } | 251 | } |
| 255 | 252 | ||
| 256 | if (pkey->ameth->item_sign) { | 253 | if (pkey->ameth->item_sign != NULL) { |
| 257 | rv = pkey->ameth->item_sign(ctx, it, asn, algor1, algor2, | 254 | rv = pkey->ameth->item_sign(ctx, it, asn, algor1, algor2, |
| 258 | signature); | 255 | signature); |
| 259 | if (rv == 1) { | 256 | if (rv == 1) { |
| @@ -273,6 +270,11 @@ ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, | |||
| 273 | } | 270 | } |
| 274 | 271 | ||
| 275 | if (rv == 2) { | 272 | if (rv == 2) { |
| 273 | if ((type = EVP_MD_CTX_md(ctx)) == NULL) { | ||
| 274 | ASN1error(ASN1_R_CONTEXT_NOT_INITIALISED); | ||
| 275 | return 0; | ||
| 276 | } | ||
| 277 | |||
| 276 | if (!OBJ_find_sigid_by_algs(&signid, EVP_MD_nid(type), | 278 | if (!OBJ_find_sigid_by_algs(&signid, EVP_MD_nid(type), |
| 277 | pkey->ameth->pkey_id)) { | 279 | pkey->ameth->pkey_id)) { |
| 278 | ASN1error(ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED); | 280 | ASN1error(ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED); |
