Don't crash if an unrecognised digest is used with dsa_paramgen_md
authorMatt Caswell <matt@openssl.org>
Thu, 29 Mar 2018 16:48:28 +0000 (17:48 +0100)
committerMatt Caswell <matt@openssl.org>
Thu, 5 Apr 2018 16:02:43 +0000 (17:02 +0100)
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5883)

crypto/dsa/dsa_pmeth.c

index 95f088a5ec2527cc11473bdf7429b6046160a9c5..a1cbaadc64a96a3e52c47811d9e4a4f70b574927 100644 (file)
@@ -187,9 +187,15 @@ static int pkey_dsa_ctrl_str(EVP_PKEY_CTX *ctx,
                                  NULL);
     }
     if (strcmp(type, "dsa_paramgen_md") == 0) {
+        const EVP_MD *md = EVP_get_digestbyname(value);
+
+        if (md == NULL) {
+            DSAerr(DSA_F_PKEY_DSA_CTRL_STR, DSA_R_INVALID_DIGEST_TYPE);
+            return 0;
+        }
         return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN,
                                  EVP_PKEY_CTRL_DSA_PARAMGEN_MD, 0,
-                                 (void *)EVP_get_digestbyname(value));
+                                 (void *)md);
     }
     return -2;
 }