Skip to content

Commit 934a04f

Browse files
committed
Do not dereference PKCS7 object data if not set
Fixes CVE-2023-0216 Reviewed-by: Shane Lontis <shane.lontis@oracle.com> Reviewed-by: Paul Dale <pauli@openssl.org>
1 parent f596ec8 commit 934a04f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

crypto/pkcs7/pk7_lib.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,8 @@ PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, EVP_PKEY *pkey,
414414

415415
static STACK_OF(X509) *pkcs7_get_signer_certs(const PKCS7 *p7)
416416
{
417+
if (p7->d.ptr == NULL)
418+
return NULL;
417419
if (PKCS7_type_is_signed(p7))
418420
return p7->d.sign->cert;
419421
if (PKCS7_type_is_signedAndEnveloped(p7))
@@ -423,6 +425,8 @@ static STACK_OF(X509) *pkcs7_get_signer_certs(const PKCS7 *p7)
423425

424426
static STACK_OF(PKCS7_RECIP_INFO) *pkcs7_get_recipient_info(const PKCS7 *p7)
425427
{
428+
if (p7->d.ptr == NULL)
429+
return NULL;
426430
if (PKCS7_type_is_signedAndEnveloped(p7))
427431
return p7->d.signed_and_enveloped->recipientinfo;
428432
if (PKCS7_type_is_enveloped(p7))
@@ -440,13 +444,17 @@ void ossl_pkcs7_resolve_libctx(PKCS7 *p7)
440444
const PKCS7_CTX *ctx = ossl_pkcs7_get0_ctx(p7);
441445
OSSL_LIB_CTX *libctx = ossl_pkcs7_ctx_get0_libctx(ctx);
442446
const char *propq = ossl_pkcs7_ctx_get0_propq(ctx);
443-
STACK_OF(PKCS7_RECIP_INFO) *rinfos = pkcs7_get_recipient_info(p7);
444-
STACK_OF(PKCS7_SIGNER_INFO) *sinfos = PKCS7_get_signer_info(p7);
445-
STACK_OF(X509) *certs = pkcs7_get_signer_certs(p7);
447+
STACK_OF(PKCS7_RECIP_INFO) *rinfos;
448+
STACK_OF(PKCS7_SIGNER_INFO) *sinfos;
449+
STACK_OF(X509) *certs;
446450

447-
if (ctx == NULL)
451+
if (ctx == NULL || p7->d.ptr == NULL)
448452
return;
449453

454+
rinfos = pkcs7_get_recipient_info(p7);
455+
sinfos = PKCS7_get_signer_info(p7);
456+
certs = pkcs7_get_signer_certs(p7);
457+
450458
for (i = 0; i < sk_X509_num(certs); i++)
451459
ossl_x509_set0_libctx(sk_X509_value(certs, i), libctx, propq);
452460

0 commit comments

Comments
 (0)