If oaep_md is not initialized, correctly initialize it
authorDmitry Belyavskiy <beldmit@gmail.com>
Thu, 18 May 2023 13:38:56 +0000 (15:38 +0200)
committerTomas Mraz <tomas@openssl.org>
Tue, 23 May 2023 13:10:56 +0000 (15:10 +0200)
Fixes #20993

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20994)

(cherry picked from commit c5aa719502f1ef456b27347e5f7b15c07817da4e)

providers/implementations/asymciphers/rsa_enc.c

index 568452ec56a281595a2849c57b8786e4840873ca..d1ceae546e5067c14065fb68f2fd78ebf7bfa12c 100644 (file)
@@ -161,10 +161,12 @@ static int rsa_encrypt(void *vprsactx, unsigned char *out, size_t *outlen,
             return 0;
         }
         if (prsactx->oaep_md == NULL) {
-            OPENSSL_free(tbuf);
             prsactx->oaep_md = EVP_MD_fetch(prsactx->libctx, "SHA-1", NULL);
-            ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);
-            return 0;
+            if (prsactx->oaep_md == NULL) {
+                OPENSSL_free(tbuf);
+                ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);
+                return 0;
+            }
         }
         ret =
             ossl_rsa_padding_add_PKCS1_OAEP_mgf1_ex(prsactx->libctx, tbuf,