Fix EVP_DigestInit_ex with NULL digest
authorMatt Caswell <matt@openssl.org>
Wed, 11 Mar 2015 15:41:52 +0000 (15:41 +0000)
committerMatt Caswell <matt@openssl.org>
Thu, 12 Mar 2015 09:19:24 +0000 (09:19 +0000)
Calling EVP_DigestInit_ex which has already had the digest set up for it
should be possible. You are supposed to be able to pass NULL for the type.
However currently this seg faults.

Reviewed-by: Andy Polyakov <appro@openssl.org>
crypto/evp/digest.c

index db755b1dbbad0d98786c5999795a475cb2454da3..48c7b00b4c8732f0e7bdb334670a2e4d55f663a2 100644 (file)
@@ -187,9 +187,12 @@ 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) {
-        EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_NO_DIGEST_SET);
-        return 0;
+    } else {
+        if (!ctx->digest) {
+            EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_NO_DIGEST_SET);
+            return 0;
+        }
+        type = ctx->digest;
     }
 #endif
     if (ctx->digest != type) {