]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix SNMP reporting of counters with a value >= 0xFF800000
authorHenrik Nordstrom <henrik@henriknordstrom.net>
Wed, 18 Jun 2008 18:49:32 +0000 (20:49 +0200)
committerHenrik Nordstrom <henrik@henriknordstrom.net>
Wed, 18 Jun 2008 18:49:32 +0000 (20:49 +0200)
The ASN.1 encoding of unsigned integers incorrectly compressed the value
as if it was a signed integer, truncating leading 0xFF octest, causing
0xFF800000 to be send ax 0x800000, 0xFFFF8000 as 0x8000 etc..

snmplib/asn1.c

index bfdd3fda043a10bbf723dab04014be3c02a1cb42..5ad7d7515b94c67c224f1564d842e36323c1209f 100644 (file)
@@ -324,10 +324,10 @@ asn_build_unsigned_int(u_char * data, int *datalength,
        return (NULL);
     }
     integer = *intp;
-    mask = (u_int) 0xFF << (8 * (sizeof(int) - 1));
-    /* mask is 0xFF000000 on a big-endian machine */
-    if ((u_char) ((integer & mask) >> (8 * (sizeof(int) - 1))) & 0x80) {
-       /* if MSB is set */
+    mask = (u_int) 0x80 << (8 * (sizeof(int) - 1));
+    /* mask is 0x80000000 on a big-endian machine */
+    if ((integer & mask) != 0) {
+       /* add a null byte if MSB is set, to prevent sign extension */
        add_null_byte = 1;
        intsize++;
     }
@@ -336,11 +336,11 @@ asn_build_unsigned_int(u_char * data, int *datalength,
      * this 2's complement integer. 
      * There should be no sequence of 9 consecutive 1's or 0's at the
      * most significant end of the integer.
+     * The 1's case is taken care of above by adding a null byte.
      */
     mask = (u_int) 0x1FF << ((8 * (sizeof(int) - 1)) - 1);
     /* mask is 0xFF800000 on a big-endian machine */
-    while ((((integer & mask) == 0)
-           || ((integer & mask) == mask)) && intsize > 1) {
+    while (((integer & mask) == 0) && intsize > 1) {
        intsize--;
        integer <<= 8;
     }