From: Bartel Artem Date: Fri, 24 Jan 2025 07:21:03 +0000 (+0300) Subject: EVP_DigestSign(): Check pctx != NULL X-Git-Tag: openssl-3.5.0-alpha1~673 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=93d366bea6b8175a9565501be992f41858ad44f3;p=thirdparty%2Fopenssl.git EVP_DigestSign(): Check pctx != NULL Reviewed-by: Dmitry Belyavskiy Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/26551) --- diff --git a/crypto/evp/m_sigver.c b/crypto/evp/m_sigver.c index a58c46bd062..f3ba3da56d3 100644 --- a/crypto/evp/m_sigver.c +++ b/crypto/evp/m_sigver.c @@ -575,13 +575,17 @@ int EVP_DigestSign(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen, { EVP_PKEY_CTX *pctx = ctx->pctx; + if (pctx == NULL) { + ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR); + return 0; + } + if ((ctx->flags & EVP_MD_CTX_FLAG_FINALISED) != 0) { ERR_raise(ERR_LIB_EVP, EVP_R_FINAL_ERROR); return 0; } - if (pctx != NULL - && pctx->operation == EVP_PKEY_OP_SIGNCTX + if (pctx->operation == EVP_PKEY_OP_SIGNCTX && pctx->op.sig.algctx != NULL && pctx->op.sig.signature != NULL) { if (pctx->op.sig.signature->digest_sign != NULL) { @@ -594,8 +598,8 @@ int EVP_DigestSign(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen, } } else { /* legacy */ - if (ctx->pctx->pmeth != NULL && ctx->pctx->pmeth->digestsign != NULL) - return ctx->pctx->pmeth->digestsign(ctx, sigret, siglen, tbs, tbslen); + if (pctx->pmeth != NULL && pctx->pmeth->digestsign != NULL) + return pctx->pmeth->digestsign(ctx, sigret, siglen, tbs, tbslen); } if (sigret != NULL && EVP_DigestSignUpdate(ctx, tbs, tbslen) <= 0)