[openssl] master update

tmraz at fedoraproject.org tmraz at fedoraproject.org
Mon Jan 18 14:01:51 UTC 2021


The branch master has been updated
       via  038f4dc68edd16f719ce5cf140eda2fb5b86a62a (commit)
       via  84af8027c5f2132a9166673e7a47b0f31c7cfe1d (commit)
      from  0d83b7b9036feea680ba45751df028ff5e86cd63 (commit)


- Log -----------------------------------------------------------------
commit 038f4dc68edd16f719ce5cf140eda2fb5b86a62a
Author: Shane Lontis <shane.lontis at oracle.com>
Date:   Fri Dec 11 19:24:46 2020 +1000

    Fix PKCS7 potential segfault
    
    As the code that handles libctx, propq for PKCS7 is very similar to CMS
    code, a similiar fix for issue #13624 needs to be applied.
    
    Reviewed-by: Tim Hudson <tjh at openssl.org>
    Reviewed-by: Tomas Mraz <tomas at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/13668)

commit 84af8027c5f2132a9166673e7a47b0f31c7cfe1d
Author: Shane Lontis <shane.lontis at oracle.com>
Date:   Fri Dec 11 19:19:37 2020 +1000

    CMS: Fix NULL access if d2i_CMS_bio() is not passed a CMS_ContentInfo**.
    
    Fixes #13624
    
    Reviewed-by: Tim Hudson <tjh at openssl.org>
    Reviewed-by: Tomas Mraz <tomas at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/13668)

-----------------------------------------------------------------------

Summary of changes:
 crypto/cms/cms_enc.c     |   7 +-
 crypto/cms/cms_env.c     |  20 +++--
 crypto/cms/cms_ess.c     |   5 +-
 crypto/cms/cms_io.c      |   4 +-
 crypto/cms/cms_kari.c    |  19 +++--
 crypto/cms/cms_lib.c     |  19 ++---
 crypto/cms/cms_pwri.c    |   7 +-
 crypto/cms/cms_sd.c      |  28 ++++---
 crypto/cms/cms_smime.c   |   6 +-
 crypto/pkcs7/pk7_asn1.c  |   2 +-
 crypto/pkcs7/pk7_doit.c  |  44 ++++++----
 crypto/pkcs7/pk7_lib.c   |   6 +-
 crypto/pkcs7/pk7_mime.c  |   2 +-
 crypto/pkcs7/pk7_smime.c |   3 +-
 crypto/x509/x_all.c      |   4 +-
 test/cmsapitest.c        | 212 ++++++++++++++++++++++++++++++++++++++++++++++-
 16 files changed, 318 insertions(+), 70 deletions(-)

diff --git a/crypto/cms/cms_enc.c b/crypto/cms/cms_enc.c
index 0069bde939..c7583f4088 100644
--- a/crypto/cms/cms_enc.c
+++ b/crypto/cms/cms_enc.c
@@ -37,6 +37,8 @@ BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec,
     size_t tkeylen = 0;
     int ok = 0;
     int enc, keep_key = 0;
+    OSSL_LIB_CTX *libctx = cms_ctx_get0_libctx(cms_ctx);
+    const char *propq = cms_ctx_get0_propq(cms_ctx);
 
     enc = ec->cipher ? 1 : 0;
 
@@ -60,8 +62,7 @@ BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec,
         cipher = EVP_get_cipherbyobj(calg->algorithm);
     }
     if (cipher != NULL) {
-        fetched_ciph = EVP_CIPHER_fetch(cms_ctx->libctx, EVP_CIPHER_name(cipher),
-                                        cms_ctx->propq);
+        fetched_ciph = EVP_CIPHER_fetch(libctx, EVP_CIPHER_name(cipher), propq);
         if (fetched_ciph != NULL)
             cipher = fetched_ciph;
     }
@@ -82,7 +83,7 @@ BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec,
         /* Generate a random IV if we need one */
         ivlen = EVP_CIPHER_CTX_iv_length(ctx);
         if (ivlen > 0) {
-            if (RAND_bytes_ex(cms_ctx->libctx, iv, ivlen) <= 0)
+            if (RAND_bytes_ex(libctx, iv, ivlen) <= 0)
                 goto err;
             piv = iv;
         }
diff --git a/crypto/cms/cms_env.c b/crypto/cms/cms_env.c
index 15ebe1b86b..d2f630146e 100644
--- a/crypto/cms/cms_env.c
+++ b/crypto/cms/cms_env.c
@@ -181,7 +181,8 @@ void cms_RecipientInfos_set_cmsctx(CMS_ContentInfo *cms)
                 break;
             case CMS_RECIPINFO_TRANS:
                 ri->d.ktri->cms_ctx = ctx;
-                x509_set0_libctx(ri->d.ktri->recip, ctx->libctx, ctx->propq);
+                x509_set0_libctx(ri->d.ktri->recip, cms_ctx_get0_libctx(ctx),
+                                 cms_ctx_get0_propq(ctx));
                 break;
             case CMS_RECIPINFO_KEK:
                 ri->d.kekri->cms_ctx = ctx;
@@ -310,8 +311,9 @@ static int cms_RecipientInfo_ktri_init(CMS_RecipientInfo *ri, X509 *recip,
     ktri->recip = recip;
 
     if (flags & CMS_KEY_PARAM) {
-        ktri->pctx = EVP_PKEY_CTX_new_from_pkey(ctx->libctx, ktri->pkey,
-                                                ctx->propq);
+        ktri->pctx = EVP_PKEY_CTX_new_from_pkey(cms_ctx_get0_libctx(ctx),
+                                                ktri->pkey,
+                                                cms_ctx_get0_propq(ctx));
         if (ktri->pctx == NULL)
             return 0;
         if (EVP_PKEY_encrypt_init(ktri->pctx) <= 0)
@@ -470,7 +472,8 @@ static int cms_RecipientInfo_ktri_encrypt(const CMS_ContentInfo *cms,
         if (!cms_env_asn1_ctrl(ri, 0))
             goto err;
     } else {
-        pctx = EVP_PKEY_CTX_new_from_pkey(ctx->libctx, ktri->pkey, ctx->propq);
+        pctx = EVP_PKEY_CTX_new_from_pkey(cms_ctx_get0_libctx(ctx), ktri->pkey,
+                                          cms_ctx_get0_propq(ctx));
         if (pctx == NULL)
             return 0;
 
@@ -524,6 +527,8 @@ static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms,
     EVP_CIPHER *fetched_cipher = NULL;
     CMS_EncryptedContentInfo *ec;
     const CMS_CTX *ctx = cms_get0_cmsctx(cms);
+    OSSL_LIB_CTX *libctx = cms_ctx_get0_libctx(ctx);
+    const char *propq = cms_ctx_get0_propq(ctx);
 
     ec = cms_get0_env_enc_content(cms);
 
@@ -538,7 +543,7 @@ static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms,
         const char *name = OBJ_nid2sn(OBJ_obj2nid(calg->algorithm));
 
         (void)ERR_set_mark();
-        fetched_cipher = EVP_CIPHER_fetch(ctx->libctx, name, ctx->propq);
+        fetched_cipher = EVP_CIPHER_fetch(libctx, name, propq);
 
         if (fetched_cipher != NULL)
             cipher = fetched_cipher;
@@ -555,7 +560,7 @@ static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms,
         EVP_CIPHER_free(fetched_cipher);
     }
 
-    ktri->pctx = EVP_PKEY_CTX_new_from_pkey(ctx->libctx, pkey, ctx->propq);
+    ktri->pctx = EVP_PKEY_CTX_new_from_pkey(libctx, pkey, propq);
     if (ktri->pctx == NULL)
         goto err;
 
@@ -808,7 +813,8 @@ static EVP_CIPHER *cms_get_key_wrap_cipher(size_t keylen, const CMS_CTX *ctx)
     default:
         return NULL;
     }
-    return EVP_CIPHER_fetch(ctx->libctx, alg, ctx->propq);
+    return EVP_CIPHER_fetch(cms_ctx_get0_libctx(ctx), alg,
+                            cms_ctx_get0_propq(ctx));
 }
 
 
diff --git a/crypto/cms/cms_ess.c b/crypto/cms/cms_ess.c
index ba05d4695c..9b02bb4363 100644
--- a/crypto/cms/cms_ess.c
+++ b/crypto/cms/cms_ess.c
@@ -219,8 +219,9 @@ static int cms_msgSigDigest(CMS_SignerInfo *si,
     if (md == NULL)
         return 0;
     if (!asn1_item_digest_ex(ASN1_ITEM_rptr(CMS_Attributes_Verify), md,
-                             si->signedAttrs, dig, diglen, si->cms_ctx->libctx,
-                             si->cms_ctx->propq))
+                             si->signedAttrs, dig, diglen,
+                             cms_ctx_get0_libctx(si->cms_ctx),
+                             cms_ctx_get0_propq(si->cms_ctx)))
         return 0;
     return 1;
 }
diff --git a/crypto/cms/cms_io.c b/crypto/cms/cms_io.c
index a12ac0d0f4..f09038a158 100644
--- a/crypto/cms/cms_io.c
+++ b/crypto/cms/cms_io.c
@@ -38,7 +38,7 @@ CMS_ContentInfo *d2i_CMS_bio(BIO *bp, CMS_ContentInfo **cms)
     CMS_ContentInfo *ci;
 
     ci = ASN1_item_d2i_bio(ASN1_ITEM_rptr(CMS_ContentInfo), bp, cms);
-    if (ci != NULL && cms != NULL)
+    if (ci != NULL)
         cms_resolve_libctx(ci);
     return ci;
 }
@@ -97,7 +97,7 @@ CMS_ContentInfo *SMIME_read_CMS_ex(BIO *bio, BIO **bcont, CMS_ContentInfo **cms)
     ci = (CMS_ContentInfo *)SMIME_read_ASN1_ex(bio, bcont,
                                                ASN1_ITEM_rptr(CMS_ContentInfo),
                                                (ASN1_VALUE **)cms);
-    if (ci != NULL && cms != NULL)
+    if (ci != NULL)
         cms_resolve_libctx(ci);
     return ci;
 }
diff --git a/crypto/cms/cms_kari.c b/crypto/cms/cms_kari.c
index a9a35b4300..b343bf4c95 100644
--- a/crypto/cms/cms_kari.c
+++ b/crypto/cms/cms_kari.c
@@ -168,8 +168,8 @@ int CMS_RecipientInfo_kari_set0_pkey_and_peer(CMS_RecipientInfo *ri, EVP_PKEY *p
     if (pk == NULL)
         return 1;
 
-    pctx = EVP_PKEY_CTX_new_from_pkey(kari->cms_ctx->libctx, pk,
-                                      kari->cms_ctx->propq);
+    pctx = EVP_PKEY_CTX_new_from_pkey(cms_ctx_get0_libctx(kari->cms_ctx), pk,
+                                      cms_ctx_get0_propq(kari->cms_ctx));
     if (pctx == NULL || EVP_PKEY_derive_init(pctx) <= 0)
         goto err;
 
@@ -284,8 +284,10 @@ static int cms_kari_create_ephemeral_key(CMS_KeyAgreeRecipientInfo *kari,
     EVP_PKEY *ekey = NULL;
     int rv = 0;
     const CMS_CTX *ctx = kari->cms_ctx;
+    OSSL_LIB_CTX *libctx = cms_ctx_get0_libctx(ctx);
+    const char *propq = cms_ctx_get0_propq(ctx);
 
-    pctx = EVP_PKEY_CTX_new_from_pkey(ctx->libctx, pk, ctx->propq);
+    pctx = EVP_PKEY_CTX_new_from_pkey(libctx, pk, propq);
     if (pctx == NULL)
         goto err;
     if (EVP_PKEY_keygen_init(pctx) <= 0)
@@ -293,7 +295,7 @@ static int cms_kari_create_ephemeral_key(CMS_KeyAgreeRecipientInfo *kari,
     if (EVP_PKEY_keygen(pctx, &ekey) <= 0)
         goto err;
     EVP_PKEY_CTX_free(pctx);
-    pctx = EVP_PKEY_CTX_new_from_pkey(ctx->libctx, ekey, ctx->propq);
+    pctx = EVP_PKEY_CTX_new_from_pkey(libctx, ekey, propq);
     if (pctx == NULL)
         goto err;
     if (EVP_PKEY_derive_init(pctx) <= 0)
@@ -315,7 +317,9 @@ static int cms_kari_set_originator_private_key(CMS_KeyAgreeRecipientInfo *kari,
     int rv = 0;
     const CMS_CTX *ctx = kari->cms_ctx;
 
-    pctx = EVP_PKEY_CTX_new_from_pkey(ctx->libctx, originatorPrivKey, ctx->propq);
+    pctx = EVP_PKEY_CTX_new_from_pkey(cms_ctx_get0_libctx(ctx),
+                                      originatorPrivKey,
+                                      cms_ctx_get0_propq(ctx));
     if (pctx == NULL)
         goto err;
     if (EVP_PKEY_derive_init(pctx) <= 0)
@@ -455,8 +459,9 @@ static int cms_wrap_init(CMS_KeyAgreeRecipientInfo *kari,
     else
         kekcipher_name = SN_id_aes256_wrap;
 enc:
-    fetched_kekcipher = EVP_CIPHER_fetch(cms_ctx->libctx, kekcipher_name,
-                                         cms_ctx->propq);
+    fetched_kekcipher = EVP_CIPHER_fetch(cms_ctx_get0_libctx(cms_ctx),
+                                         kekcipher_name,
+                                         cms_ctx_get0_propq(cms_ctx));
     if (fetched_kekcipher == NULL)
         return 0;
     ret = EVP_EncryptInit_ex(ctx, fetched_kekcipher, NULL, NULL, NULL);
diff --git a/crypto/cms/cms_lib.c b/crypto/cms/cms_lib.c
index 427f62c56c..62029b8931 100644
--- a/crypto/cms/cms_lib.c
+++ b/crypto/cms/cms_lib.c
@@ -30,7 +30,7 @@ CMS_ContentInfo *d2i_CMS_ContentInfo(CMS_ContentInfo **a,
 
     ci = (CMS_ContentInfo *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
                                           (CMS_ContentInfo_it()));
-    if (ci != NULL && a != NULL)
+    if (ci != NULL)
         cms_resolve_libctx(ci);
     return ci;
 }
@@ -80,12 +80,12 @@ const CMS_CTX *cms_get0_cmsctx(const CMS_ContentInfo *cms)
 
 OSSL_LIB_CTX *cms_ctx_get0_libctx(const CMS_CTX *ctx)
 {
-    return ctx->libctx;
+    return ctx != NULL ? ctx->libctx : NULL;
 }
 
 const char *cms_ctx_get0_propq(const CMS_CTX *ctx)
 {
-    return ctx->propq;
+    return ctx != NULL ? ctx->propq : NULL;
 }
 
 void cms_resolve_libctx(CMS_ContentInfo *ci)
@@ -93,12 +93,10 @@ void cms_resolve_libctx(CMS_ContentInfo *ci)
     int i;
     CMS_CertificateChoices *cch;
     STACK_OF(CMS_CertificateChoices) **pcerts;
-    const CMS_CTX *ctx;
+    const CMS_CTX *ctx = cms_get0_cmsctx(ci);
+    OSSL_LIB_CTX *libctx = cms_ctx_get0_libctx(ctx);
+    const char *propq = cms_ctx_get0_propq(ctx);
 
-    if (ci == NULL)
-        return;
-
-    ctx = cms_get0_cmsctx(ci);
     cms_SignerInfos_set_cmsctx(ci);
     cms_RecipientInfos_set_cmsctx(ci);
 
@@ -107,7 +105,7 @@ void cms_resolve_libctx(CMS_ContentInfo *ci)
         for (i = 0; i < sk_CMS_CertificateChoices_num(*pcerts); i++) {
             cch = sk_CMS_CertificateChoices_value(*pcerts, i);
             if (cch->type == CMS_CERTCHOICE_CERT)
-                x509_set0_libctx(cch->d.certificate, ctx->libctx, ctx->propq);
+                x509_set0_libctx(cch->d.certificate, libctx, propq);
         }
     }
 }
@@ -411,7 +409,8 @@ BIO *cms_DigestAlgorithm_init_bio(X509_ALGOR *digestAlgorithm,
     alg = OBJ_nid2sn(OBJ_obj2nid(digestoid));
 
     (void)ERR_set_mark();
-    fetched_digest = EVP_MD_fetch(ctx->libctx, alg, ctx->propq);
+    fetched_digest = EVP_MD_fetch(cms_ctx_get0_libctx(ctx), alg,
+                                  cms_ctx_get0_propq(ctx));
 
     if (fetched_digest != NULL)
         digest = fetched_digest;
diff --git a/crypto/cms/cms_pwri.c b/crypto/cms/cms_pwri.c
index 8b55f7d0a8..ecfa1f5ffe 100644
--- a/crypto/cms/cms_pwri.c
+++ b/crypto/cms/cms_pwri.c
@@ -93,7 +93,7 @@ CMS_RecipientInfo *CMS_add0_recipient_password(CMS_ContentInfo *cms,
     ivlen = EVP_CIPHER_CTX_iv_length(ctx);
 
     if (ivlen > 0) {
-        if (RAND_bytes_ex(cms_ctx->libctx, iv, ivlen) <= 0)
+        if (RAND_bytes_ex(cms_ctx_get0_libctx(cms_ctx), iv, ivlen) <= 0)
             goto err;
         if (EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv) <= 0) {
             ERR_raise(ERR_LIB_CMS, ERR_R_EVP_LIB);
@@ -262,7 +262,7 @@ static int kek_wrap_key(unsigned char *out, size_t *outlen,
         memcpy(out + 4, in, inlen);
         /* Add random padding to end */
         if (olen > inlen + 4
-            && RAND_bytes_ex(cms_ctx->libctx, out + 4 + inlen,
+            && RAND_bytes_ex(cms_ctx_get0_libctx(cms_ctx), out + 4 + inlen,
                              olen - 4 - inlen) <= 0)
             return 0;
         /* Encrypt twice */
@@ -316,7 +316,8 @@ int cms_RecipientInfo_pwri_crypt(const CMS_ContentInfo *cms,
     }
 
     name = OBJ_nid2sn(OBJ_obj2nid(kekalg->algorithm));
-    kekcipher = EVP_CIPHER_fetch(cms_ctx->libctx, name, cms_ctx->propq);
+    kekcipher = EVP_CIPHER_fetch(cms_ctx_get0_libctx(cms_ctx), name,
+                                 cms_ctx_get0_propq(cms_ctx));
 
     if (kekcipher == NULL) {
         ERR_raise(ERR_LIB_CMS, CMS_R_UNKNOWN_CIPHER);
diff --git a/crypto/cms/cms_sd.c b/crypto/cms/cms_sd.c
index 96b92bdc63..d803a6c006 100644
--- a/crypto/cms/cms_sd.c
+++ b/crypto/cms/cms_sd.c
@@ -407,8 +407,9 @@ CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
 
     if (flags & CMS_KEY_PARAM) {
         if (flags & CMS_NOATTR) {
-            si->pctx = EVP_PKEY_CTX_new_from_pkey(ctx->libctx, si->pkey,
-                                                  ctx->propq);
+            si->pctx = EVP_PKEY_CTX_new_from_pkey(cms_ctx_get0_libctx(ctx),
+                                                  si->pkey,
+                                                  cms_ctx_get0_propq(ctx));
             if (si->pctx == NULL)
                 goto err;
             if (EVP_PKEY_sign_init(si->pctx) <= 0)
@@ -416,7 +417,8 @@ CMS_SignerInfo *CMS_add1_signer(CMS_ContentInfo *cms,
             if (EVP_PKEY_CTX_set_signature_md(si->pctx, md) <= 0)
                 goto err;
         } else if (EVP_DigestSignInit_ex(si->mctx, &si->pctx, EVP_MD_name(md),
-                                         ctx->libctx, ctx->propq, pk) <= 0) {
+                                         cms_ctx_get0_libctx(ctx),
+                                         cms_ctx_get0_propq(ctx), pk) <= 0) {
             goto err;
         }
     }
@@ -678,8 +680,9 @@ static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms,
             ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
             goto err;
         }
-        if (!EVP_SignFinal_ex(mctx, sig, &siglen, si->pkey, ctx->libctx,
-                              ctx->propq)) {
+        if (!EVP_SignFinal_ex(mctx, sig, &siglen, si->pkey,
+                              cms_ctx_get0_libctx(ctx),
+                              cms_ctx_get0_propq(ctx))) {
             ERR_raise(ERR_LIB_CMS, CMS_R_SIGNFINAL_ERROR);
             OPENSSL_free(sig);
             goto err;
@@ -737,8 +740,8 @@ int CMS_SignerInfo_sign(CMS_SignerInfo *si)
         pctx = si->pctx;
     else {
         EVP_MD_CTX_reset(mctx);
-        if (EVP_DigestSignInit_ex(mctx, &pctx, md_name, ctx->libctx, ctx->propq,
-                                  si->pkey) <= 0)
+        if (EVP_DigestSignInit_ex(mctx, &pctx, md_name, cms_ctx_get0_libctx(ctx),
+                                  cms_ctx_get0_propq(ctx), si->pkey) <= 0)
             goto err;
         si->pctx = pctx;
     }
@@ -815,6 +818,8 @@ int CMS_SignerInfo_verify(CMS_SignerInfo *si)
     const EVP_MD *md;
     EVP_MD *fetched_md = NULL;
     const CMS_CTX *ctx = si->cms_ctx;
+    OSSL_LIB_CTX *libctx = cms_ctx_get0_libctx(ctx);
+    const char *propq = cms_ctx_get0_propq(ctx);
 
     if (si->pkey == NULL) {
         ERR_raise(ERR_LIB_CMS, CMS_R_NO_PUBLIC_KEY);
@@ -827,7 +832,7 @@ int CMS_SignerInfo_verify(CMS_SignerInfo *si)
     name = OBJ_nid2sn(OBJ_obj2nid(si->digestAlgorithm->algorithm));
 
     (void)ERR_set_mark();
-    fetched_md = EVP_MD_fetch(ctx->libctx, name, ctx->propq);
+    fetched_md = EVP_MD_fetch(libctx, name, propq);
 
     if (fetched_md != NULL)
         md = fetched_md;
@@ -845,8 +850,8 @@ int CMS_SignerInfo_verify(CMS_SignerInfo *si)
         goto err;
     }
     mctx = si->mctx;
-    if (EVP_DigestVerifyInit_ex(mctx, &si->pctx, EVP_MD_name(md), ctx->libctx,
-                                NULL, si->pkey) <= 0)
+    if (EVP_DigestVerifyInit_ex(mctx, &si->pctx, EVP_MD_name(md), libctx,
+                                propq, si->pkey) <= 0)
         goto err;
 
     if (!cms_sd_asn1_ctrl(si, 1))
@@ -953,7 +958,8 @@ int CMS_SignerInfo_verify_content(CMS_SignerInfo *si, BIO *chain)
         const EVP_MD *md = EVP_MD_CTX_md(mctx);
         const CMS_CTX *ctx = si->cms_ctx;
 
-        pkctx = EVP_PKEY_CTX_new_from_pkey(ctx->libctx, si->pkey, ctx->propq);
+        pkctx = EVP_PKEY_CTX_new_from_pkey(cms_ctx_get0_libctx(ctx), si->pkey,
+                                           cms_ctx_get0_propq(ctx));
         if (pkctx == NULL)
             goto err;
         if (EVP_PKEY_verify_init(pkctx) <= 0)
diff --git a/crypto/cms/cms_smime.c b/crypto/cms/cms_smime.c
index 5c903f204b..6c62d904eb 100644
--- a/crypto/cms/cms_smime.c
+++ b/crypto/cms/cms_smime.c
@@ -264,7 +264,8 @@ static int cms_signerinfo_verify_cert(CMS_SignerInfo *si,
     X509 *signer;
     int i, j, r = 0;
 
-    ctx = X509_STORE_CTX_new_ex(cms_ctx->libctx, cms_ctx->propq);
+    ctx = X509_STORE_CTX_new_ex(cms_ctx_get0_libctx(cms_ctx),
+                                cms_ctx_get0_propq(cms_ctx));
     if (ctx == NULL) {
         ERR_raise(ERR_LIB_CMS, ERR_R_MALLOC_FAILURE);
         goto err;
@@ -567,7 +568,8 @@ CMS_ContentInfo *CMS_sign_receipt(CMS_SignerInfo *si,
 
     /* Initialize signed data */
 
-    cms = CMS_sign_ex(NULL, NULL, certs, NULL, flags, ctx->libctx, ctx->propq);
+    cms = CMS_sign_ex(NULL, NULL, certs, NULL, flags, cms_ctx_get0_libctx(ctx),
+                      cms_ctx_get0_propq(ctx));
     if (cms == NULL)
         goto err;
 
diff --git a/crypto/pkcs7/pk7_asn1.c b/crypto/pkcs7/pk7_asn1.c
index 9820d1b8eb..9136d9afaf 100644
--- a/crypto/pkcs7/pk7_asn1.c
+++ b/crypto/pkcs7/pk7_asn1.c
@@ -68,7 +68,7 @@ PKCS7 *d2i_PKCS7(PKCS7 **a, const unsigned char **in, long len)
     PKCS7 *ret;
 
     ret = (PKCS7 *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, (PKCS7_it()));
-    if (ret != NULL && a != NULL)
+    if (ret != NULL)
         pkcs7_resolve_libctx(ret);
     return ret;
 }
diff --git a/crypto/pkcs7/pk7_doit.c b/crypto/pkcs7/pk7_doit.c
index 111088703d..d6acfd4754 100644
--- a/crypto/pkcs7/pk7_doit.c
+++ b/crypto/pkcs7/pk7_doit.c
@@ -69,7 +69,8 @@ static int pkcs7_bio_add_digest(BIO **pbio, X509_ALGOR *alg,
     name = OBJ_nid2sn(OBJ_obj2nid(alg->algorithm));
 
     (void)ERR_set_mark();
-    fetched = EVP_MD_fetch(ctx->libctx, name, ctx->propq);
+    fetched = EVP_MD_fetch(pkcs7_ctx_get0_libctx(ctx), name,
+                           pkcs7_ctx_get0_propq(ctx));
     if (fetched != NULL)
         md = fetched;
     else
@@ -113,7 +114,8 @@ static int pkcs7_encode_rinfo(PKCS7_RECIP_INFO *ri,
     if (pkey == NULL)
         return 0;
 
-    pctx = EVP_PKEY_CTX_new_from_pkey(ctx->libctx, pkey, ctx->propq);
+    pctx = EVP_PKEY_CTX_new_from_pkey(pkcs7_ctx_get0_libctx(ctx), pkey,
+                                      pkcs7_ctx_get0_propq(ctx));
     if (pctx == NULL)
         return 0;
 
@@ -161,7 +163,8 @@ static int pkcs7_decrypt_rinfo(unsigned char **pek, int *peklen,
     int ret = -1;
     const PKCS7_CTX *ctx = ri->ctx;
 
-    pctx = EVP_PKEY_CTX_new_from_pkey(ctx->libctx, pkey, ctx->propq);
+    pctx = EVP_PKEY_CTX_new_from_pkey(pkcs7_ctx_get0_libctx(ctx), pkey,
+                                      pkcs7_ctx_get0_propq(ctx));
     if (pctx == NULL)
         return -1;
 
@@ -222,12 +225,16 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
     PKCS7_RECIP_INFO *ri = NULL;
     ASN1_OCTET_STRING *os = NULL;
     const PKCS7_CTX *p7_ctx;
+    OSSL_LIB_CTX *libctx;
+    const char *propq;
 
     if (p7 == NULL) {
         ERR_raise(ERR_LIB_PKCS7, PKCS7_R_INVALID_NULL_POINTER);
         return NULL;
     }
     p7_ctx = pkcs7_get0_ctx(p7);
+    libctx = pkcs7_ctx_get0_libctx(p7_ctx);
+    propq = pkcs7_ctx_get0_propq(p7_ctx);
 
     /*
      * The content field in the PKCS7 ContentInfo is optional, but that really
@@ -304,13 +311,13 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
         ivlen = EVP_CIPHER_iv_length(evp_cipher);
         xalg->algorithm = OBJ_nid2obj(EVP_CIPHER_type(evp_cipher));
         if (ivlen > 0)
-            if (RAND_bytes_ex(p7_ctx->libctx, iv, ivlen) <= 0)
+            if (RAND_bytes_ex(libctx, iv, ivlen) <= 0)
                 goto err;
 
         (void)ERR_set_mark();
-        fetched_cipher = EVP_CIPHER_fetch(p7_ctx->libctx,
+        fetched_cipher = EVP_CIPHER_fetch(libctx,
                                           EVP_CIPHER_name(evp_cipher),
-                                          p7_ctx->propq);
+                                          propq);
         (void)ERR_pop_to_mark();
         if (fetched_cipher != NULL)
             cipher = fetched_cipher;
@@ -411,6 +418,8 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
     int eklen = 0, tkeylen = 0;
     const char *name;
     const PKCS7_CTX *p7_ctx;
+    OSSL_LIB_CTX *libctx;
+    const char *propq;
 
     if (p7 == NULL) {
         ERR_raise(ERR_LIB_PKCS7, PKCS7_R_INVALID_NULL_POINTER);
@@ -418,6 +427,8 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
     }
 
     p7_ctx = pkcs7_get0_ctx(p7);
+    libctx = pkcs7_ctx_get0_libctx(p7_ctx);
+    propq = pkcs7_ctx_get0_propq(p7_ctx);
 
     if (p7->d.ptr == NULL) {
         ERR_raise(ERR_LIB_PKCS7, PKCS7_R_NO_CONTENT);
@@ -452,7 +463,7 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
         name = OBJ_nid2sn(OBJ_obj2nid(enc_alg->algorithm));
 
         (void)ERR_set_mark();
-        evp_cipher = EVP_CIPHER_fetch(p7_ctx->libctx, name, p7_ctx->propq);
+        evp_cipher = EVP_CIPHER_fetch(libctx, name, propq);
         if (evp_cipher != NULL)
             cipher = evp_cipher;
         else
@@ -473,7 +484,7 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
         name = OBJ_nid2sn(OBJ_obj2nid(enc_alg->algorithm));
 
         (void)ERR_set_mark();
-        evp_cipher = EVP_CIPHER_fetch(p7_ctx->libctx, name, p7_ctx->propq);
+        evp_cipher = EVP_CIPHER_fetch(libctx, name, propq);
         if (evp_cipher != NULL)
             cipher = evp_cipher;
         else
@@ -509,7 +520,7 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
             name = OBJ_nid2sn(OBJ_obj2nid(xa->algorithm));
 
             (void)ERR_set_mark();
-            evp_md = EVP_MD_fetch(p7_ctx->libctx, name, p7_ctx->propq);
+            evp_md = EVP_MD_fetch(libctx, name, propq);
             if (evp_md != NULL)
                 md = evp_md;
             else
@@ -843,7 +854,8 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
                     goto err;
 
                 if (!EVP_SignFinal_ex(ctx_tmp, abuf, &abuflen, si->pkey,
-                                      p7_ctx->libctx, p7_ctx->propq)) {
+                                      pkcs7_ctx_get0_libctx(p7_ctx),
+                                      pkcs7_ctx_get0_propq(p7_ctx))) {
                     OPENSSL_free(abuf);
                     ERR_raise(ERR_LIB_PKCS7, ERR_R_EVP_LIB);
                     goto err;
@@ -914,8 +926,9 @@ int PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_INFO *si)
         goto err;
     }
 
-    if (EVP_DigestSignInit_ex(mctx, &pctx, EVP_MD_name(md), ctx->libctx,
-                              ctx->propq, si->pkey) <= 0)
+    if (EVP_DigestSignInit_ex(mctx, &pctx, EVP_MD_name(md),
+                              pkcs7_ctx_get0_libctx(ctx),
+                              pkcs7_ctx_get0_propq(ctx), si->pkey) <= 0)
         goto err;
 
     /*
@@ -1063,6 +1076,8 @@ int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
     BIO *btmp;
     EVP_PKEY *pkey;
     const PKCS7_CTX *ctx = pkcs7_get0_ctx(p7);
+    OSSL_LIB_CTX *libctx = pkcs7_ctx_get0_libctx(ctx);
+    const char *propq = pkcs7_ctx_get0_propq(ctx);
 
     mdc_tmp = EVP_MD_CTX_new();
     if (mdc_tmp == NULL) {
@@ -1129,7 +1144,7 @@ int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
         }
 
         (void)ERR_set_mark();
-        fetched_md = EVP_MD_fetch(ctx->libctx, OBJ_nid2sn(md_type), ctx->propq);
+        fetched_md = EVP_MD_fetch(libctx, OBJ_nid2sn(md_type), propq);
 
         if (fetched_md != NULL)
             md = fetched_md;
@@ -1162,8 +1177,7 @@ int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
         goto err;
     }
 
-    i = EVP_VerifyFinal_ex(mdc_tmp, os->data, os->length, pkey, ctx->libctx,
-                           ctx->propq);
+    i = EVP_VerifyFinal_ex(mdc_tmp, os->data, os->length, pkey, libctx, propq);
     if (i <= 0) {
         ERR_raise(ERR_LIB_PKCS7, PKCS7_R_SIGNATURE_FAILURE);
         ret = -1;
diff --git a/crypto/pkcs7/pk7_lib.c b/crypto/pkcs7/pk7_lib.c
index 1cc233e89d..35a757062b 100644
--- a/crypto/pkcs7/pk7_lib.c
+++ b/crypto/pkcs7/pk7_lib.c
@@ -401,6 +401,8 @@ void pkcs7_resolve_libctx(PKCS7 *p7)
 {
     int i;
     const PKCS7_CTX *ctx = pkcs7_get0_ctx(p7);
+    OSSL_LIB_CTX *libctx = pkcs7_ctx_get0_libctx(ctx);
+    const char *propq = pkcs7_ctx_get0_propq(ctx);
     STACK_OF(PKCS7_RECIP_INFO) *rinfos = pkcs7_get_recipient_info(p7);
     STACK_OF(PKCS7_SIGNER_INFO) *sinfos = PKCS7_get_signer_info(p7);
     STACK_OF(X509) *certs = pkcs7_get_signer_certs(p7);
@@ -409,12 +411,12 @@ void pkcs7_resolve_libctx(PKCS7 *p7)
         return;
 
     for (i = 0; i < sk_X509_num(certs); i++)
-        x509_set0_libctx(sk_X509_value(certs, i), ctx->libctx, ctx->propq);
+        x509_set0_libctx(sk_X509_value(certs, i), libctx, propq);
 
     for (i = 0; i < sk_PKCS7_RECIP_INFO_num(rinfos); i++) {
         PKCS7_RECIP_INFO *ri = sk_PKCS7_RECIP_INFO_value(rinfos, i);
 
-        x509_set0_libctx(ri->cert, ctx->libctx, ctx->propq);
+        x509_set0_libctx(ri->cert, libctx, propq);
     }
 
     for (i = 0; i < sk_PKCS7_SIGNER_INFO_num(sinfos); i++) {
diff --git a/crypto/pkcs7/pk7_mime.c b/crypto/pkcs7/pk7_mime.c
index 381df40a94..40f87f8043 100644
--- a/crypto/pkcs7/pk7_mime.c
+++ b/crypto/pkcs7/pk7_mime.c
@@ -52,7 +52,7 @@ PKCS7 *SMIME_read_PKCS7_ex(BIO *bio, BIO **bcont, PKCS7 **p7)
 
     ret = (PKCS7 *)SMIME_read_ASN1_ex(bio, bcont, ASN1_ITEM_rptr(PKCS7),
                                       (ASN1_VALUE **)p7);
-    if (ret != NULL && p7 != NULL)
+    if (ret != NULL)
         pkcs7_resolve_libctx(ret);
     return ret;
 }
diff --git a/crypto/pkcs7/pk7_smime.c b/crypto/pkcs7/pk7_smime.c
index 770534d9f6..b5dfc916a5 100644
--- a/crypto/pkcs7/pk7_smime.c
+++ b/crypto/pkcs7/pk7_smime.c
@@ -266,7 +266,8 @@ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
 
     /* Now verify the certificates */
     p7_ctx = pkcs7_get0_ctx(p7);
-    cert_ctx = X509_STORE_CTX_new_ex(p7_ctx->libctx, p7_ctx->propq);
+    cert_ctx = X509_STORE_CTX_new_ex(pkcs7_ctx_get0_libctx(p7_ctx),
+                                     pkcs7_ctx_get0_propq(p7_ctx));
     if (cert_ctx == NULL)
         goto err;
     if (!(flags & PKCS7_NOVERIFY))
diff --git a/crypto/x509/x_all.c b/crypto/x509/x_all.c
index 9d9079f7f5..3a0e8bc181 100644
--- a/crypto/x509/x_all.c
+++ b/crypto/x509/x_all.c
@@ -178,7 +178,7 @@ PKCS7 *d2i_PKCS7_fp(FILE *fp, PKCS7 **p7)
     PKCS7 *ret;
 
     ret = ASN1_item_d2i_fp(ASN1_ITEM_rptr(PKCS7), fp, p7);
-    if (ret != NULL && p7 != NULL)
+    if (ret != NULL)
         pkcs7_resolve_libctx(ret);
     return ret;
 }
@@ -194,7 +194,7 @@ PKCS7 *d2i_PKCS7_bio(BIO *bp, PKCS7 **p7)
     PKCS7 *ret;
 
     ret = ASN1_item_d2i_bio(ASN1_ITEM_rptr(PKCS7), bp, p7);
-    if (ret != NULL && p7 != NULL)
+    if (ret != NULL)
         pkcs7_resolve_libctx(ret);
     return ret;
 }
diff --git a/test/cmsapitest.c b/test/cmsapitest.c
index a69fcc949d..373cc930b0 100644
--- a/test/cmsapitest.c
+++ b/test/cmsapitest.c
@@ -78,6 +78,216 @@ static int test_encrypt_decrypt_aes_256_gcm(void)
     return test_encrypt_decrypt(EVP_aes_256_gcm());
 }
 
+static int test_d2i_CMS_bio_NULL(void)
+{
+    BIO *bio;
+    CMS_ContentInfo *cms = NULL;
+    int ret = 0;
+
+    /*
+     * Test data generated using:
+     * openssl cms -sign -md sha256 -signer ./test/certs/rootCA.pem -inkey \
+     * ./test/certs/rootCA.key -nodetach -outform DER -in ./in.txt -out out.der \
+     * -nosmimecap
+     */
+    static const unsigned char cms_data[] = {
+        0x30, 0x82, 0x05, 0xc5, 0x06, 0x09, 0x2a, 0x86,
+        0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0,
+        0x82, 0x05, 0xb6, 0x30, 0x82, 0x05, 0xb2, 0x02,
+        0x01, 0x01, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x09,
+        0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02,
+        0x01, 0x30, 0x1c, 0x06, 0x09, 0x2a, 0x86, 0x48,
+        0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0xa0, 0x0f,
+        0x04, 0x0d, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20,
+        0x57, 0x6f, 0x72, 0x6c, 0x64, 0x0d, 0x0a, 0xa0,
+        0x82, 0x03, 0x83, 0x30, 0x82, 0x03, 0x7f, 0x30,
+        0x82, 0x02, 0x67, 0xa0, 0x03, 0x02, 0x01, 0x02,
+        0x02, 0x09, 0x00, 0x88, 0x43, 0x29, 0xcb, 0xc2,
+        0xeb, 0x15, 0x9a, 0x30, 0x0d, 0x06, 0x09, 0x2a,
+        0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
+        0x05, 0x00, 0x30, 0x56, 0x31, 0x0b, 0x30, 0x09,
+        0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x41,
+        0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55,
+        0x04, 0x08, 0x0c, 0x0a, 0x53, 0x6f, 0x6d, 0x65,
+        0x2d, 0x53, 0x74, 0x61, 0x74, 0x65, 0x31, 0x21,
+        0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
+        0x18, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65,
+        0x74, 0x20, 0x57, 0x69, 0x64, 0x67, 0x69, 0x74,
+        0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, 0x74,
+        0x64, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55,
+        0x04, 0x03, 0x0c, 0x06, 0x72, 0x6f, 0x6f, 0x74,
+        0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x35,
+        0x30, 0x37, 0x30, 0x32, 0x31, 0x33, 0x31, 0x35,
+        0x31, 0x31, 0x5a, 0x17, 0x0d, 0x33, 0x35, 0x30,
+        0x37, 0x30, 0x32, 0x31, 0x33, 0x31, 0x35, 0x31,
+        0x31, 0x5a, 0x30, 0x56, 0x31, 0x0b, 0x30, 0x09,
+        0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x41,
+        0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55,
+        0x04, 0x08, 0x0c, 0x0a, 0x53, 0x6f, 0x6d, 0x65,
+        0x2d, 0x53, 0x74, 0x61, 0x74, 0x65, 0x31, 0x21,
+        0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c,
+        0x18, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65,
+        0x74, 0x20, 0x57, 0x69, 0x64, 0x67, 0x69, 0x74,
+        0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, 0x74,
+        0x64, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55,
+        0x04, 0x03, 0x0c, 0x06, 0x72, 0x6f, 0x6f, 0x74,
+        0x43, 0x41, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d,
+        0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
+        0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01,
+        0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82,
+        0x01, 0x01, 0x00, 0xc0, 0xf1, 0x6b, 0x77, 0x88,
+        0xac, 0x35, 0xdf, 0xfb, 0x73, 0x53, 0x2f, 0x92,
+        0x80, 0x2f, 0x74, 0x16, 0x32, 0x4d, 0xf5, 0x10,
+        0x20, 0x6f, 0x6c, 0x3a, 0x8e, 0xd1, 0xdc, 0x6b,
+        0xe1, 0x2e, 0x3e, 0xc3, 0x04, 0x0f, 0xbf, 0x9b,
+        0xc4, 0xc9, 0x12, 0xd1, 0xe4, 0x0b, 0x45, 0x97,
+        0xe5, 0x06, 0xcd, 0x66, 0x3a, 0xe1, 0xe0, 0xe2,
+        0x2b, 0xdf, 0xa2, 0xc4, 0xec, 0x7b, 0xd3, 0x3d,
+        0x3c, 0x8a, 0xff, 0x5e, 0x74, 0xa0, 0xab, 0xa7,
+        0x03, 0x6a, 0x16, 0x5b, 0x5e, 0x92, 0xc4, 0x7e,
+        0x5b, 0x79, 0x8a, 0x69, 0xd4, 0xbc, 0x83, 0x5e,
+        0xae, 0x42, 0x92, 0x74, 0xa5, 0x2b, 0xe7, 0x00,
+        0xc1, 0xa9, 0xdc, 0xd5, 0xb1, 0x53, 0x07, 0x0f,
+        0x73, 0xf7, 0x8e, 0xad, 0x14, 0x3e, 0x25, 0x9e,
+        0xe5, 0x1e, 0xe6, 0xcc, 0x91, 0xcd, 0x95, 0x0c,
+        0x80, 0x44, 0x20, 0xc3, 0xfd, 0x17, 0xcf, 0x91,
+        0x3d, 0x63, 0x10, 0x1c, 0x14, 0x5b, 0xfb, 0xc3,
+        0xa8, 0xc1, 0x88, 0xb2, 0x77, 0xff, 0x9c, 0xdb,
+        0xfc, 0x6a, 0x44, 0x44, 0x44, 0xf7, 0x85, 0xec,
+        0x08, 0x2c, 0xd4, 0xdf, 0x81, 0xa3, 0x79, 0xc9,
+        0xfe, 0x1e, 0x9b, 0x93, 0x16, 0x53, 0xb7, 0x97,
+        0xab, 0xbe, 0x4f, 0x1a, 0xa5, 0xe2, 0xfa, 0x46,
+        0x05, 0xe4, 0x0d, 0x9c, 0x2a, 0xa4, 0xcc, 0xb9,
+        0x1e, 0x21, 0xa0, 0x6c, 0xc4, 0xab, 0x59, 0xb0,
+        0x40, 0x39, 0xbb, 0xf9, 0x88, 0xad, 0xfd, 0xdf,
+        0x8d, 0xb4, 0x0b, 0xaf, 0x7e, 0x41, 0xe0, 0x21,
+        0x3c, 0xc8, 0x33, 0x45, 0x49, 0x84, 0x2f, 0x93,
+        0x06, 0xee, 0xfd, 0x4f, 0xed, 0x4f, 0xf3, 0xbc,
+        0x9b, 0xde, 0xfc, 0x25, 0x5e, 0x55, 0xd5, 0x75,
+        0xd4, 0xc5, 0x7b, 0x3a, 0x40, 0x35, 0x06, 0x9f,
+        0xc4, 0x84, 0xb4, 0x6c, 0x93, 0x0c, 0xaf, 0x37,
+        0x5a, 0xaf, 0xb6, 0x41, 0x4d, 0x26, 0x23, 0x1c,
+        0xb8, 0x02, 0xb3, 0x02, 0x03, 0x01, 0x00, 0x01,
+        0xa3, 0x50, 0x30, 0x4e, 0x30, 0x0c, 0x06, 0x03,
+        0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01,
+        0x01, 0xff, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d,
+        0x0e, 0x04, 0x16, 0x04, 0x14, 0x85, 0x56, 0x89,
+        0x35, 0xe2, 0x9f, 0x00, 0x1a, 0xe1, 0x86, 0x03,
+        0x0b, 0x4b, 0xaf, 0x76, 0x12, 0x6b, 0x33, 0x6d,
+        0xfd, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23,
+        0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x85, 0x56,
+        0x89, 0x35, 0xe2, 0x9f, 0x00, 0x1a, 0xe1, 0x86,
+        0x03, 0x0b, 0x4b, 0xaf, 0x76, 0x12, 0x6b, 0x33,
+        0x6d, 0xfd, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
+        0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05,
+        0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x32, 0x0a,
+        0xbf, 0x2a, 0x0a, 0xe2, 0xbb, 0x4f, 0x43, 0xce,
+        0x88, 0xda, 0x5a, 0x39, 0x10, 0x37, 0x80, 0xbb,
+        0x37, 0x2d, 0x5e, 0x2d, 0x88, 0xdd, 0x26, 0x69,
+        0x9c, 0xe7, 0xb4, 0x98, 0x20, 0xb1, 0x25, 0xe6,
+        0x61, 0x59, 0x6d, 0x12, 0xec, 0x9b, 0x87, 0xbe,
+        0x57, 0xe1, 0x12, 0x05, 0xc5, 0x04, 0xf1, 0x17,
+        0xce, 0x14, 0xb8, 0x1c, 0x92, 0xd4, 0x95, 0x95,
+        0x2c, 0x5b, 0x28, 0x89, 0xfb, 0x72, 0x9c, 0x20,
+        0xd3, 0x32, 0x81, 0xa8, 0x85, 0xec, 0xc8, 0x08,
+        0x7b, 0xa8, 0x59, 0x5b, 0x3a, 0x6c, 0x31, 0xab,
+        0x52, 0xe2, 0x66, 0xcd, 0x14, 0x49, 0x5c, 0xf3,
+        0xd3, 0x3e, 0x62, 0xbc, 0x91, 0x16, 0xb4, 0x1c,
+        0xf5, 0xdd, 0x54, 0xaa, 0x3c, 0x61, 0x97, 0x79,
+        0xac, 0xe4, 0xc8, 0x43, 0x35, 0xc3, 0x0f, 0xfc,
+        0xf3, 0x70, 0x1d, 0xaf, 0xf0, 0x9c, 0x8a, 0x2a,
+        0x92, 0x93, 0x48, 0xaa, 0xd0, 0xe8, 0x47, 0xbe,
+        0x35, 0xc1, 0xc6, 0x7b, 0x6d, 0xda, 0xfa, 0x5d,
+        0x57, 0x45, 0xf3, 0xea, 0x41, 0x8f, 0x36, 0xc1,
+        0x3c, 0xf4, 0x52, 0x7f, 0x6e, 0x31, 0xdd, 0xba,
+        0x9a, 0xbc, 0x70, 0x56, 0x71, 0x38, 0xdc, 0x49,
+        0x57, 0x0c, 0xfd, 0x91, 0x17, 0xc5, 0xea, 0x87,
+        0xe5, 0x23, 0x74, 0x19, 0xb2, 0xb6, 0x99, 0x0c,
+        0x6b, 0xa2, 0x05, 0xf8, 0x51, 0x68, 0xed, 0x97,
+        0xe0, 0xdf, 0x62, 0xf9, 0x7e, 0x7a, 0x3a, 0x44,
+        0x71, 0x83, 0x57, 0x28, 0x49, 0x88, 0x69, 0xb5,
+        0x14, 0x1e, 0xda, 0x46, 0xe3, 0x6e, 0x78, 0xe1,
+        0xcb, 0x8f, 0xb5, 0x98, 0xb3, 0x2d, 0x6e, 0x5b,
+        0xb7, 0xf6, 0x93, 0x24, 0x14, 0x1f, 0xa4, 0xf6,
+        0x69, 0xbd, 0xff, 0x4c, 0x52, 0x50, 0x02, 0xc5,
+        0x43, 0x8d, 0x14, 0xe2, 0xd0, 0x75, 0x9f, 0x12,
+        0x5e, 0x94, 0x89, 0xd1, 0xef, 0x77, 0x89, 0x7d,
+        0x89, 0xd9, 0x9e, 0x76, 0x99, 0x24, 0x31, 0x82,
+        0x01, 0xf7, 0x30, 0x82, 0x01, 0xf3, 0x02, 0x01,
+        0x01, 0x30, 0x63, 0x30, 0x56, 0x31, 0x0b, 0x30,
+        0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
+        0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03,
+        0x55, 0x04, 0x08, 0x0c, 0x0a, 0x53, 0x6f, 0x6d,
+        0x65, 0x2d, 0x53, 0x74, 0x61, 0x74, 0x65, 0x31,
+        0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a,
+        0x0c, 0x18, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e,
+        0x65, 0x74, 0x20, 0x57, 0x69, 0x64, 0x67, 0x69,
+        0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c,
+        0x74, 0x64, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03,
+        0x55, 0x04, 0x03, 0x0c, 0x06, 0x72, 0x6f, 0x6f,
+        0x74, 0x43, 0x41, 0x02, 0x09, 0x00, 0x88, 0x43,
+        0x29, 0xcb, 0xc2, 0xeb, 0x15, 0x9a, 0x30, 0x0b,
+        0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
+        0x04, 0x02, 0x01, 0xa0, 0x69, 0x30, 0x18, 0x06,
+        0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
+        0x09, 0x03, 0x31, 0x0b, 0x06, 0x09, 0x2a, 0x86,
+        0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0x30,
+        0x1c, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
+        0x0d, 0x01, 0x09, 0x05, 0x31, 0x0f, 0x17, 0x0d,
+        0x32, 0x30, 0x31, 0x32, 0x31, 0x31, 0x30, 0x39,
+        0x30, 0x30, 0x31, 0x33, 0x5a, 0x30, 0x2f, 0x06,
+        0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
+        0x09, 0x04, 0x31, 0x22, 0x04, 0x20, 0xb0, 0x80,
+        0x22, 0xd3, 0x15, 0xcf, 0x1e, 0xb1, 0x2d, 0x26,
+        0x65, 0xbd, 0xed, 0x0e, 0x6a, 0xf4, 0x06, 0x53,
+        0xc0, 0xa0, 0xbe, 0x97, 0x52, 0x32, 0xfb, 0x49,
+        0xbc, 0xbd, 0x02, 0x1c, 0xfc, 0x36, 0x30, 0x0d,
+        0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
+        0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, 0x01,
+        0x00, 0x37, 0x44, 0x39, 0x08, 0xb2, 0x19, 0x52,
+        0x35, 0x9c, 0xd0, 0x67, 0x87, 0xae, 0xb8, 0x1c,
+        0x80, 0xf4, 0x03, 0x29, 0x2e, 0xe3, 0x76, 0x4a,
+        0xb0, 0x98, 0x10, 0x00, 0x9a, 0x30, 0xdb, 0x05,
+        0x28, 0x53, 0x34, 0x31, 0x14, 0xbd, 0x87, 0xb9,
+        0x4d, 0x45, 0x07, 0x97, 0xa3, 0x57, 0x0b, 0x7e,
+        0xd1, 0x67, 0xfb, 0x4e, 0x0f, 0x5b, 0x90, 0xb2,
+        0x6f, 0xe6, 0xce, 0x49, 0xdd, 0x72, 0x46, 0x71,
+        0x26, 0xa1, 0x1b, 0x98, 0x23, 0x7d, 0x69, 0x73,
+        0x84, 0xdc, 0xf9, 0xd2, 0x1c, 0x6d, 0xf6, 0xf5,
+        0x17, 0x49, 0x6e, 0x9d, 0x4d, 0xf1, 0xe2, 0x43,
+        0x29, 0x53, 0x55, 0xa5, 0x22, 0x1e, 0x89, 0x2c,
+        0xaf, 0xf2, 0x43, 0x47, 0xd5, 0xfa, 0xad, 0xe7,
+        0x89, 0x60, 0xbf, 0x96, 0x35, 0x6f, 0xc2, 0x99,
+        0xb7, 0x55, 0xc5, 0xe3, 0x04, 0x25, 0x1b, 0xf6,
+        0x7e, 0xf2, 0x2b, 0x14, 0xa9, 0x57, 0x96, 0xbe,
+        0xbd, 0x6e, 0x95, 0x44, 0x94, 0xbd, 0xaf, 0x9a,
+        0x6d, 0x77, 0x55, 0x5e, 0x6c, 0xf6, 0x32, 0x37,
+        0xec, 0xef, 0xe5, 0x81, 0xb0, 0xe3, 0x35, 0xc7,
+        0x86, 0xea, 0x47, 0x59, 0x38, 0xb6, 0x16, 0xfb,
+        0x1d, 0x10, 0x55, 0x48, 0xb1, 0x44, 0x33, 0xde,
+        0xf6, 0x29, 0xbe, 0xbf, 0xbc, 0x71, 0x3e, 0x49,
+        0xba, 0xe7, 0x9f, 0x4d, 0x6c, 0xfb, 0xec, 0xd2,
+        0xe0, 0x12, 0xa9, 0x7c, 0xc9, 0x9a, 0x7b, 0x85,
+        0x83, 0xb8, 0xca, 0xdd, 0xf6, 0xb7, 0x15, 0x75,
+        0x7b, 0x4a, 0x69, 0xcf, 0x0a, 0xc7, 0x80, 0x01,
+        0xe7, 0x94, 0x16, 0x7f, 0x8d, 0x3c, 0xfa, 0x1f,
+        0x05, 0x71, 0x76, 0x15, 0xb0, 0xf6, 0x61, 0x30,
+        0x58, 0x16, 0xbe, 0x1b, 0xd1, 0x93, 0xc4, 0x1a,
+        0x91, 0x0c, 0x48, 0xe2, 0x1c, 0x8e, 0xa5, 0xc5,
+        0xa7, 0x81, 0x44, 0x48, 0x3b, 0x10, 0xc2, 0x74,
+        0x07, 0xdf, 0xa8, 0xae, 0x57, 0xee, 0x7f, 0xe3,
+        0x6a
+    };
+
+    ret = TEST_ptr(bio = BIO_new_mem_buf(cms_data, sizeof(cms_data)))
+          && TEST_ptr(cms = d2i_CMS_bio(bio, NULL))
+          && TEST_true(CMS_verify(cms, NULL, NULL, NULL, NULL,
+                                  CMS_NO_SIGNER_CERT_VERIFY));
+    CMS_ContentInfo_free(cms);
+    BIO_free(bio);
+    return ret;
+}
+
 OPT_TEST_DECLARE_USAGE("certfile privkeyfile\n")
 
 int setup_tests(void)
@@ -121,7 +331,7 @@ int setup_tests(void)
     ADD_TEST(test_encrypt_decrypt_aes_128_gcm);
     ADD_TEST(test_encrypt_decrypt_aes_192_gcm);
     ADD_TEST(test_encrypt_decrypt_aes_256_gcm);
-
+    ADD_TEST(test_d2i_CMS_bio_NULL);
     return 1;
 }
 


More information about the openssl-commits mailing list