From: Henrik Nordstrom Date: Wed, 18 Jun 2008 18:49:32 +0000 (+0200) Subject: Fix SNMP reporting of counters with a value >= 0xFF800000 X-Git-Tag: SQUID_3_1_0_1~49^2~201 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ce1206d7fe8421c46a7e77c0944dc67eac0cf880;p=thirdparty%2Fsquid.git Fix SNMP reporting of counters with a value >= 0xFF800000 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.. --- diff --git a/snmplib/asn1.c b/snmplib/asn1.c index bfdd3fda04..5ad7d7515b 100644 --- a/snmplib/asn1.c +++ b/snmplib/asn1.c @@ -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; }