]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix ASN.1 encoding of long SNMP OIDs (#2149)
authorAlex Rousskov <rousskov@measurement-factory.com>
Sat, 30 Aug 2025 06:49:36 +0000 (06:49 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Sat, 30 Aug 2025 08:53:00 +0000 (08:53 +0000)
lib/snmplib/asn1.c

index 81f2051fbe7cd1e2b6a51c9b44d3539881260c92..2852c26b220f8e27084a969f4d8f55e3bb0c8d95 100644 (file)
@@ -735,6 +735,7 @@ asn_build_objid(u_char * data, int *datalength,
      * lastbyte ::= 0 7bitvalue
      */
     u_char buf[MAX_OID_LEN];
+    u_char *bufEnd = buf + sizeof(buf);
     u_char *bp = buf;
     oid *op = objid;
     int asnlength;
@@ -753,6 +754,10 @@ asn_build_objid(u_char * data, int *datalength,
     while (objidlength-- > 0) {
         subid = *op++;
         if (subid < 127) {  /* off by one? */
+            if (bp >= bufEnd) {
+                snmp_set_api_error(SNMPERR_ASN_ENCODE);
+                return (NULL);
+            }
             *bp++ = subid;
         } else {
             mask = 0x7F;    /* handle subid == 0 case */
@@ -770,8 +775,16 @@ asn_build_objid(u_char * data, int *datalength,
                 /* fix a mask that got truncated above */
                 if (mask == 0x1E00000)
                     mask = 0xFE00000;
+                if (bp >= bufEnd) {
+                    snmp_set_api_error(SNMPERR_ASN_ENCODE);
+                    return (NULL);
+                }
                 *bp++ = (u_char) (((subid & mask) >> bits) | ASN_BIT8);
             }
+            if (bp >= bufEnd) {
+                snmp_set_api_error(SNMPERR_ASN_ENCODE);
+                return (NULL);
+            }
             *bp++ = (u_char) (subid & mask);
         }
     }