]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
When calling ASN1_item_i2d () check both returned length and allocated pointer
authorXZ-X <xu1415@purdue.edu>
Mon, 22 Jul 2024 18:33:02 +0000 (14:33 -0400)
committerTomas Mraz <tomas@openssl.org>
Tue, 20 Aug 2024 09:45:14 +0000 (11:45 +0200)
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/24979)

crypto/asn1/a_dup.c
crypto/asn1/a_i2d_fp.c
crypto/cms/cms_sd.c
crypto/pkcs7/pk7_attr.c
crypto/pkcs7/pk7_doit.c

index 23d1d63808979f629541e578e4ed6241fea21655..33dc3ff58e780be4c4da9eee3419790cdaefed28 100644 (file)
@@ -75,7 +75,7 @@ void *ASN1_item_dup(const ASN1_ITEM *it, const void *x)
     }
 
     i = ASN1_item_i2d(x, &b, it);
-    if (b == NULL) {
+    if (i < 0 || b == NULL) {
         ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
         return NULL;
     }
index e30f1f2a17f65c2056d35754d4c96794d202fe0e..ccee6fccb0aaa5f0de612c7d2aa362ae283695d9 100644 (file)
@@ -88,7 +88,7 @@ int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, const void *x)
     int i, j = 0, n, ret = 1;
 
     n = ASN1_item_i2d(x, &b, it);
-    if (b == NULL) {
+    if (n < 0 || b == NULL) {
         ERR_raise(ERR_LIB_ASN1, ERR_R_ASN1_LIB);
         return 0;
     }
index a76e795df588b2411ee1a0a8bc7bd79330b80298..a0badeb44d844e9d004d7d1790730f5dfc14c443 100644 (file)
@@ -862,7 +862,7 @@ int CMS_SignerInfo_sign(CMS_SignerInfo *si)
 
     alen = ASN1_item_i2d((ASN1_VALUE *)si->signedAttrs, &abuf,
                          ASN1_ITEM_rptr(CMS_Attributes_Sign));
-    if (!abuf)
+    if (alen < 0 || abuf == NULL)
         goto err;
     if (EVP_DigestSignUpdate(mctx, abuf, alen) <= 0)
         goto err;
index a12d65bb8e31f844b596c2137fe598660f31a1de..cef22365eb76415d186242614fa7dc136825398a 100644 (file)
@@ -28,6 +28,10 @@ int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si,
     }
     seq->length = ASN1_item_i2d((ASN1_VALUE *)cap, &seq->data,
                                 ASN1_ITEM_rptr(X509_ALGORS));
+    if (seq->length <= 0 || seq->data == NULL) {
+        ASN1_STRING_free(seq);
+        return 1;
+    }
     if (!PKCS7_add_signed_attribute(si, NID_SMIMECapabilities,
                                     V_ASN1_SEQUENCE, seq)) {
         ASN1_STRING_free(seq);
index 4748d4207d9f06d8d8f230f4af27b550251b4d61..6a53d8912cec5cde2d333b914eab5f5085da49ca 100644 (file)
@@ -920,7 +920,7 @@ int PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_INFO *si)
 
     alen = ASN1_item_i2d((ASN1_VALUE *)si->auth_attr, &abuf,
                          ASN1_ITEM_rptr(PKCS7_ATTR_SIGN));
-    if (!abuf)
+    if (alen < 0 || abuf == NULL)
         goto err;
     if (EVP_DigestSignUpdate(mctx, abuf, alen) <= 0)
         goto err;
@@ -1102,7 +1102,7 @@ int PKCS7_signatureVerify(BIO *bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
 
         alen = ASN1_item_i2d((ASN1_VALUE *)sk, &abuf,
                              ASN1_ITEM_rptr(PKCS7_ATTR_VERIFY));
-        if (alen <= 0) {
+        if (alen <= 0 || abuf == NULL) {
             ERR_raise(ERR_LIB_PKCS7, ERR_R_ASN1_LIB);
             ret = -1;
             goto err;