]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
The tag value must fit into int
authorTomas Mraz <tomas@openssl.foundation>
Tue, 5 May 2026 15:01:42 +0000 (17:01 +0200)
committerNorbert Pocs <norbertp@openssl.org>
Thu, 7 May 2026 12:11:41 +0000 (14:11 +0200)
We cannot allow an unbounded tag value as this is an O(n^2) algorithm
and the tag cannot be larger than INT_MAX anyway.
Fixes 35852da1d9e24cb74034b2f418cef3a58203b127

Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.foundation>
Reviewed-by: Simo Sorce <simo@redhat.com>
MergeDate: Thu May  7 12:12:25 2026
(Merged from https://github.com/openssl/openssl/pull/31091)

crypto/asn1/a_d2i_fp.c

index 629d517028050cf26cf901750f52f93b2faac411..8f9e26768975f0a572a5dc063781fac6c8194991 100644 (file)
@@ -169,8 +169,15 @@ int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
 
         diff--;
         if ((*(q++) & V_ASN1_PRIMITIVE_TAG) == V_ASN1_PRIMITIVE_TAG) {
+            unsigned int i = 0;
             /* Multi-byte tag.  See if we have the whole thing yet */
             do {
+                if (i > 4) {
+                    /* The tag value must fit into int */
+                    ERR_raise(ERR_LIB_ASN1, ASN1_R_HEADER_TOO_LONG);
+                    goto err;
+                }
+                ++i;
                 diff--;
             } while (diff > 0 && *(q++) & 0x80);