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:35:54 +0000 (08:35 +0200)
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18202)

crypto/evp/ctrl_params_translate.c

index 74df2fd1a3047bd942eb5e438c66edf948453503..08137ab256a036a6e15783b6ff1ec94b6d9ea64f 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);
     }