From aca6f3e82d427bccd47f2b1b5e88dbb87c93a590 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Tue, 11 Jul 2023 14:10:49 +1000 Subject: [PATCH] Clear OpenSSL errors on EVP failures (cherry picked from commit 4ea926934a8d08cece0469406357bbd9fd8492d8) --- lib/isc/hmac.c | 5 +++++ lib/isc/iterated_hash.c | 3 ++- lib/isc/md.c | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/isc/hmac.c b/lib/isc/hmac.c index 15a217f218..bc35befc1e 100644 --- a/lib/isc/hmac.c +++ b/lib/isc/hmac.c @@ -11,6 +11,7 @@ * information regarding copyright ownership. */ +#include #include #include @@ -61,6 +62,7 @@ isc_hmac_init(isc_hmac_t *hmac, const void *key, const size_t keylen, if (EVP_DigestSignInit(hmac, NULL, md_type, NULL, pkey) != 1) { EVP_PKEY_free(pkey); + ERR_clear_error(); return (ISC_R_CRYPTOFAILURE); } @@ -74,6 +76,7 @@ isc_hmac_reset(isc_hmac_t *hmac) { REQUIRE(hmac != NULL); if (EVP_MD_CTX_reset(hmac) != 1) { + ERR_clear_error(); return (ISC_R_CRYPTOFAILURE); } @@ -89,6 +92,7 @@ isc_hmac_update(isc_hmac_t *hmac, const unsigned char *buf, const size_t len) { } if (EVP_DigestSignUpdate(hmac, buf, len) != 1) { + ERR_clear_error(); return (ISC_R_CRYPTOFAILURE); } @@ -105,6 +109,7 @@ isc_hmac_final(isc_hmac_t *hmac, unsigned char *digest, size_t len = *digestlen; if (EVP_DigestSignFinal(hmac, digest, &len) != 1) { + ERR_clear_error(); return (ISC_R_CRYPTOFAILURE); } diff --git a/lib/isc/iterated_hash.c b/lib/isc/iterated_hash.c index de1f3a36a3..80d219c56b 100644 --- a/lib/isc/iterated_hash.c +++ b/lib/isc/iterated_hash.c @@ -13,6 +13,7 @@ #include +#include #include #include @@ -127,7 +128,7 @@ isc_iterated_hash(unsigned char *out, const unsigned int hashalg, fail: EVP_MD_CTX_free(ctx); EVP_MD_free(md); - + ERR_clear_error(); return (0); } diff --git a/lib/isc/md.c b/lib/isc/md.c index d094cfa0ec..53ce2c16c7 100644 --- a/lib/isc/md.c +++ b/lib/isc/md.c @@ -47,6 +47,7 @@ isc_md_init(isc_md_t *md, const isc_md_type_t *md_type) { } if (EVP_DigestInit_ex(md, md_type, NULL) != 1) { + ERR_clear_error(); return (ISC_R_CRYPTOFAILURE); } @@ -58,6 +59,7 @@ isc_md_reset(isc_md_t *md) { REQUIRE(md != NULL); if (EVP_MD_CTX_reset(md) != 1) { + ERR_clear_error(); return (ISC_R_CRYPTOFAILURE); } @@ -73,6 +75,7 @@ isc_md_update(isc_md_t *md, const unsigned char *buf, const size_t len) { } if (EVP_DigestUpdate(md, buf, len) != 1) { + ERR_clear_error(); return (ISC_R_CRYPTOFAILURE); } @@ -85,6 +88,7 @@ isc_md_final(isc_md_t *md, unsigned char *digest, unsigned int *digestlen) { REQUIRE(digest != NULL); if (EVP_DigestFinal_ex(md, digest, digestlen) != 1) { + ERR_clear_error(); return (ISC_R_CRYPTOFAILURE); }