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 14:44:24 +0000 (15:44 +0100)
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5800)

crypto/dsa/dsa_pmeth.c

index 88744a9ce2469f81fca9e12a380910065e31b4e4..493427667e783fc0bd5ddac9dc2daa843b69e0fe 100644 (file)
@@ -189,9 +189,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;
 }