From a3d5cd95358503fa0bb15316bd2a188eeccacb5d Mon Sep 17 00:00:00 2001
From: yangwu <yangwu29@h-partners.com>
Date: Mon, 6 Jul 2026 15:27:29 +0800
Subject: [PATCH 1/4] Fix potential NULL dereference processing CMS
 PasswordRecipientInfo Avoid NULL dereferencing when keyDerivationAlgorithm is
 absent in CMS PasswordRecipientInfo.

Fixes CVE-2026-42766

Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.foundation>
MergeDate: Mon Jun  8 18:57:52 2026
(cherry picked from commit f019b72c589071a73acda9812775389a857884c9)Fix potential NULL dereference processing CMS PasswordRecipientInfo
Avoid NULL dereferencing when keyDerivationAlgorithm is absent
in CMS PasswordRecipientInfo.

Fixes CVE-2026-42766

origin:https://github.com/openssl/openssl/commit/056d06c1918fafbb98c1c85a02e4c47cc4e199ce#diff-f1bfc666d9b7824d9ed556807b57e864cdf0409939d565b7dc20b53182335f53R370-R372

Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.foundation>
MergeDate: Mon Jun  8 18:57:52 2026
(cherry picked from commit f019b72c589071a73acda9812775389a857884c9)
---
 CryptoPkg/Library/OpensslLib/openssl/crypto/cms/cms_pwri.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/CryptoPkg/Library/OpensslLib/openssl/crypto/cms/cms_pwri.c b/CryptoPkg/Library/OpensslLib/openssl/crypto/cms/cms_pwri.c
index 2940c6b9..6e8ccce2 100644
--- a/CryptoPkg/Library/OpensslLib/openssl/crypto/cms/cms_pwri.c
+++ b/CryptoPkg/Library/OpensslLib/openssl/crypto/cms/cms_pwri.c
@@ -351,6 +351,12 @@ int ossl_cms_RecipientInfo_pwri_crypt(const CMS_ContentInfo *cms,
 
     /* Finish password based key derivation to setup key in "ctx" */
 
+    if (algtmp == NULL) {
+        ERR_raise_data(ERR_LIB_CMS, CMS_R_INVALID_KEY_ENCRYPTION_PARAMETER,
+            "Missing KeyDerivationAlgorithm");
+        goto err;
+    }
+
     if (EVP_PBE_CipherInit(algtmp->algorithm,
                            (char *)pwri->pass, pwri->passlen,
                            algtmp->parameter, kekctx, en_de) < 0) {
-- 
2.43.0