[AGENT++] SNMP++ 64-bit bug

Robert Hancock hancock at sedsystems.ca
Tue Jan 23 18:11:50 CET 2007


I've found a problem in SNMP++ version 3.2.21a when running on a Linux x86_64
platform. In src/asn1.cpp there is this code:

     *length = ntohl(*length);
     // ntohl even on ALPHA (DEC/COMPAQ) 64bit platforms works on 32bit int,
     // whereas long is 64bit - therefore:
#ifdef __osf__
     *length >>= (8 * ((sizeof(int)) - lengthbyte));
#else
     *length >>= (8 * ((sizeof(long)) - lengthbyte));
#endif

The comment is wrong, ntohl works on 32-bit values on all platforms as per the
Open Group spec, not just Alpha, so the ifdef should not be there. I changed the
code to simply:

     *length = ntohl(*length);
     *length >>= (8 * ((sizeof(int)) - lengthbyte));

Without this fix, the agent wouldn't respond to any SNMP requests, it always
complained about "bad parse of length".

-- 
Robert Hancock
Programmer Analyst
SED Systems
Email: hancock at sedsystems.ca




More information about the AGENTPP mailing list