]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix regression in EVP_DigestInit_ex: crash when called with NULL type
authorTomas Mraz <tmraz@fedoraproject.org>
Fri, 13 Nov 2020 14:57:27 +0000 (15:57 +0100)
committerTomas Mraz <tmraz@fedoraproject.org>
Thu, 26 Nov 2020 16:39:26 +0000 (17:39 +0100)
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/13402)

crypto/evp/digest.c

index 19d9face898ea5113d1bf9f4df555232c30f1295..b0ce61f935c55838f91a51d523ea3d9fe5181f9f 100644 (file)
@@ -170,8 +170,15 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
         ctx->provctx = NULL;
     }
 
-    if (type != NULL)
+    if (type != NULL) {
         ctx->reqdigest = type;
+    } else {
+        if (ctx->digest == NULL) {
+            ERR_raise(ERR_LIB_EVP, EVP_R_NO_DIGEST_SET);
+            return 0;
+        }
+        type = ctx->digest;
+    }
 
     /* TODO(3.0): Legacy work around code below. Remove this */
 #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE)
@@ -292,12 +299,6 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
             ctx->engine = impl;
         } else
             ctx->engine = NULL;
-    } else {
-        if (!ctx->digest) {
-            ERR_raise(ERR_LIB_EVP, EVP_R_NO_DIGEST_SET);
-            return 0;
-        }
-        type = ctx->digest;
     }
 #endif
     if (ctx->digest != type) {