diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/evp/digest.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c index 59c98b57b8..fd42318044 100644 --- a/src/lib/libcrypto/evp/digest.c +++ b/src/lib/libcrypto/evp/digest.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: digest.c,v 1.32 2021/12/12 21:30:13 tb Exp $ */ | 1 | /* $OpenBSD: digest.c,v 1.33 2022/01/09 15:15: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 | * |
| @@ -282,6 +282,12 @@ EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) | |||
| 282 | EVP_MD_CTX_cleanup(out); | 282 | EVP_MD_CTX_cleanup(out); |
| 283 | memcpy(out, in, sizeof *out); | 283 | memcpy(out, in, sizeof *out); |
| 284 | 284 | ||
| 285 | /* | ||
| 286 | * Because of the EVP_PKEY_CTX_dup() below, EVP_MD_CTX_cleanup() needs | ||
| 287 | * to free out->pctx in all cases (even if this flag is set on in). | ||
| 288 | */ | ||
| 289 | EVP_MD_CTX_clear_flags(out, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX); | ||
| 290 | |||
| 285 | if (in->md_data && out->digest->ctx_size) { | 291 | if (in->md_data && out->digest->ctx_size) { |
| 286 | if (tmp_buf) { | 292 | if (tmp_buf) { |
| 287 | out->md_data = tmp_buf; | 293 | out->md_data = tmp_buf; |
| @@ -383,7 +389,12 @@ EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) | |||
| 383 | if (ctx->digest && ctx->digest->ctx_size && ctx->md_data && | 389 | if (ctx->digest && ctx->digest->ctx_size && ctx->md_data && |
| 384 | !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)) | 390 | !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)) |
| 385 | freezero(ctx->md_data, ctx->digest->ctx_size); | 391 | freezero(ctx->md_data, ctx->digest->ctx_size); |
| 386 | EVP_PKEY_CTX_free(ctx->pctx); | 392 | /* |
| 393 | * If EVP_MD_CTX_FLAG_KEEP_PKEY_CTX is set, EVP_MD_CTX_set_pkey() was | ||
| 394 | * called and its strange API contract implies we don't own ctx->pctx. | ||
| 395 | */ | ||
| 396 | if (!EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX)) | ||
| 397 | EVP_PKEY_CTX_free(ctx->pctx); | ||
| 387 | #ifndef OPENSSL_NO_ENGINE | 398 | #ifndef OPENSSL_NO_ENGINE |
| 388 | ENGINE_finish(ctx->engine); | 399 | ENGINE_finish(ctx->engine); |
| 389 | #endif | 400 | #endif |
