check the return value of BN_dup() in rsa_lib.c:1248
authorx2018 <xkernel.wang@foxmail.com>
Tue, 30 Nov 2021 12:33:32 +0000 (20:33 +0800)
committerTomas Mraz <tomas@openssl.org>
Thu, 2 Dec 2021 08:51:16 +0000 (09:51 +0100)
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17168)

crypto/rsa/rsa_lib.c

index 6433282597091f4e489e91cb24fc270599064408..a8a6d6c758e92a0b65824fbe0613bce780fd21b0 100644 (file)
@@ -1244,8 +1244,11 @@ int EVP_PKEY_CTX_set1_rsa_keygen_pubexp(EVP_PKEY_CTX *ctx, BIGNUM *pubexp)
      * When we're dealing with a provider, there's no need to duplicate
      * pubexp, as it gets copied when transforming to an OSSL_PARAM anyway.
      */
-    if (evp_pkey_ctx_is_legacy(ctx))
+    if (evp_pkey_ctx_is_legacy(ctx)) {
         pubexp = BN_dup(pubexp);
+        if (pubexp == NULL)
+            return 0;
+    }
     ret = EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_KEYGEN,
                             EVP_PKEY_CTRL_RSA_KEYGEN_PUBEXP, 0, pubexp);
     if (evp_pkey_ctx_is_legacy(ctx) && ret <= 0)