]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Avoid NULL dereference with PKCS7_OP_SET_DETACHED_SIGNATURE
authorTomas Mraz <tomas@openssl.org>
Thu, 28 Nov 2024 09:10:28 +0000 (10:10 +0100)
committerTomas Mraz <tomas@openssl.org>
Mon, 2 Dec 2024 08:44:58 +0000 (09:44 +0100)
We would dereference p7->d.sign pointer which can be NULL.

Reported by Han Zheng.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/26078)

crypto/pkcs7/pk7_lib.c

index 043a8f9ceda9089076d6888efcef2305e5c8b76b..d7c5f1afbe4d3ccf2d2ce6963a74ff6be3219748 100644 (file)
@@ -28,6 +28,11 @@ long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg)
     /* NOTE(emilia): does not support detached digested data. */
     case PKCS7_OP_SET_DETACHED_SIGNATURE:
         if (nid == NID_pkcs7_signed) {
+            if (p7->d.sign == NULL) {
+                ERR_raise(ERR_LIB_PKCS7, PKCS7_R_NO_CONTENT);
+                ret = 0;
+                break;
+            }
             ret = p7->detached = (int)larg;
             if (ret && PKCS7_type_is_data(p7->d.sign->contents)) {
                 ASN1_OCTET_STRING *os;