]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
pkcs7: fix NULL contents dereference in PKCS7_dataFinal
authorWeidong Wang <kenazcharisma@gmail.com>
Tue, 10 Mar 2026 17:15:22 +0000 (12:15 -0500)
committerNeil Horman <nhorman@openssl.org>
Tue, 17 Mar 2026 17:04:52 +0000 (13:04 -0400)
Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Frederik Wedel-Heinen <fwh.openssl@gmail.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>
MergeDate: Tue Mar 17 17:01:53 2026
(Merged from https://github.com/openssl/openssl/pull/30351)

(cherry picked from commit 70837aa2385bc83226375d74f02fe5c03a3e0d21)

crypto/pkcs7/pk7_doit.c

index 8987cf90b69af4ee54fdcd7a418666f1a0480d0c..28d43dfaf6faf22f559e8e245e5d5b9b016dc7c1 100644 (file)
@@ -802,6 +802,10 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
         break;
     case NID_pkcs7_signed:
         si_sk = p7->d.sign->signer_info;
+        if (p7->d.sign->contents == NULL) {
+            ERR_raise(ERR_LIB_PKCS7, PKCS7_R_NO_CONTENT);
+            goto err;
+        }
         os = PKCS7_get_octet_string(p7->d.sign->contents);
         /* If detached data then the content is excluded */
         if (PKCS7_type_is_data(p7->d.sign->contents) && p7->detached) {
@@ -812,6 +816,10 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
         break;
 
     case NID_pkcs7_digest:
+        if (p7->d.digest->contents == NULL) {
+            ERR_raise(ERR_LIB_PKCS7, PKCS7_R_NO_CONTENT);
+            goto err;
+        }
         os = PKCS7_get_octet_string(p7->d.digest->contents);
         /* If detached data then the content is excluded */
         if (PKCS7_type_is_data(p7->d.digest->contents) && p7->detached) {