Fix unsafe BIO_get_md_ctx check

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/16768)
This commit is contained in:
PW Hu 2021-10-07 11:50:59 +08:00 committed by Tomas Mraz
parent 0c75a7387d
commit 59a3e7b295

View File

@ -335,7 +335,7 @@ int dgst_main(int argc, char **argv)
EVP_PKEY_CTX *pctx = NULL; EVP_PKEY_CTX *pctx = NULL;
int res; int res;
if (!BIO_get_md_ctx(bmd, &mctx)) { if (BIO_get_md_ctx(bmd, &mctx) <= 0) {
BIO_printf(bio_err, "Error getting context\n"); BIO_printf(bio_err, "Error getting context\n");
goto end; goto end;
} }
@ -362,7 +362,7 @@ int dgst_main(int argc, char **argv)
/* we use md as a filter, reading from 'in' */ /* we use md as a filter, reading from 'in' */
else { else {
EVP_MD_CTX *mctx = NULL; EVP_MD_CTX *mctx = NULL;
if (!BIO_get_md_ctx(bmd, &mctx)) { if (BIO_get_md_ctx(bmd, &mctx) <= 0) {
BIO_printf(bio_err, "Error getting context\n"); BIO_printf(bio_err, "Error getting context\n");
goto end; goto end;
} }