fix_dh_paramgen_type: Avoid crash with invalid paramgen type
authorTomas Mraz <tomas@openssl.org>
Thu, 28 Apr 2022 15:04:05 +0000 (17:04 +0200)
committerTomas Mraz <tomas@openssl.org>
Mon, 2 May 2022 06:36:42 +0000 (08:36 +0200)
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18202)

(cherry picked from commit 359dad5178285d5471f2a57a5aa99c1f588dffcb)

crypto/evp/ctrl_params_translate.c

index 0aa1c23beec70e6fbc5f2ef23b4efca9c4d516b5..7d2f501dfb1b06b65529e72767e2ffc0d6092121 100644 (file)
@@ -1072,7 +1072,11 @@ static int fix_dh_paramgen_type(enum state state,
         return 0;
 
     if (state == PRE_CTRL_STR_TO_PARAMS) {
-        ctx->p2 = (char *)ossl_dh_gen_type_id2name(atoi(ctx->p2));
+        if ((ctx->p2 = (char *)ossl_dh_gen_type_id2name(atoi(ctx->p2)))
+             == NULL) {
+            ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_VALUE);
+            return 0;
+        }
         ctx->p1 = strlen(ctx->p2);
     }