[AGENT++] Bug in asn1.cpp on 64-bit architecture

Alex Agranov Alex.Agranov at audiocodes.com
Wed Feb 4 15:06:27 CET 2009


I ported my application that uses SNMP++/AGENT++ stacks to the 64-bit SPARC Solaris box and discovered that it fails to parse incoming SNMP messages. I localized the bug and fixed it, so that now my application runs just fine.

The patch is a one-liner fix in asn_parse_length() function in asn1.cpp module.
It is related to the fact that on 64-bit architecture (both Solaris and Linux) sizeof(int)==4 but sizeof(long)==8, while on 32-bit architecture both types are 4 bytes long.

# diff -C2 asn1.cpp asn1.orig
*** asn1.cpp    Wed Feb  4 15:44:28 2009
--- asn1.orig   Wed Feb  4 15:53:48 2009
***************
*** 544,548 ****
      memcpy((char *)length, (char *)data + 1, (int)lengthbyte);
      *length = ntohl(*length);
!     *length >>= (8 * ((sizeof(unsigned long)) - lengthbyte));
      // check for length greater than 2^31
      if (*length > 0x80000000ul) {
--- 544,548 ----
      memcpy((char *)length, (char *)data + 1, (int)lengthbyte);
      *length = ntohl(*length);
!     *length >>= (8 * ((sizeof(int)) - lengthbyte));
      // check for length greater than 2^31
      if (*length > 0x80000000ul) {

I already reported before (about half a year ago) that SNMP++/AGENT++ sometimes uses 64-bit data types (long) instead of 32-bit data types (int) on 64-bit architectures. However now I can confirm that besides the minor bug described above, the ASN parser and the rest of the stack seem to  work just fine (of course we waste some memory, but it's not a big deal for me)...

Regards,
   Alex Agranov

This email and any files transmitted with it are confidential material. They are intended solely for the use of the designated individual or entity to whom they are addressed. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, use, distribution or copying of this communication is strictly prohibited and may be unlawful.

If you have received this email in error please immediately notify the sender and delete or destroy any copy of this message



More information about the AGENTPP mailing list