[SNMP4J] [PATCH] Workaround for Net-SNMP < 5.4.1 64-bit agent bug

Jeff Gehlbach jeffg at jeffg.org
Tue Oct 9 14:59:23 CEST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi!

I work on the OpenNMS project, which has for some time been using  
SNMP4J as its default protocol implementation.  Thank you for the  
fabulous work on SNMP4J!

I'm writing to propose a patch that works around a bounds-checking  
bug in the Net-SNMP project's BER library that causes OpenNMS to fail  
to discover any 64-bit host running a Net-SNMP snmpd older than  
version 5.4.1.  The BER bug in question causes IPv4 addresses to be  
encoded as 64-bit values but marked in the PDU as being four bytes  
long.  When SNMP4J decodes a RESPONSE PDU containing such a value, it  
correctly discards the variable in question.  The upshot is that  
OpenNMS cannot discover the interfaces on a node because it does not  
get a valid picture of the node's ipAddrTable.

The following patch, against Snmp4J 1.8.2, seems to effect a  
workaround for this highly annoying and destructive agent bug.  I  
(and several others) have successfully discovered and managed hosts  
exhibiting this agent bug by dropping in an SNMP4J JAR built from  
sources with this patch applied.  The addition of a property to  
enable this workaround seemed the simplest and least intrusive route,  
but I'm not married to the idea.  Feedback is earnestly solicited!

Thanks,
- -jeff


diff -ur snmp4j-1.8.2.orig/src/org/snmp4j/smi/IpAddress.java  
snmp4j-1.8.2/src/org/snmp4j/smi/IpAddress.java
- --- snmp4j-1.8.2.orig/src/org/snmp4j/smi/IpAddress.java 2007-03-10  
21:59:12.000000000 -0500
+++ snmp4j-1.8.2/src/org/snmp4j/smi/IpAddress.java      2007-08-26  
19:07:26.000000000 -0400
@@ -150,9 +150,17 @@
                              type.getValue());
      }
      if (value.length != 4) {
- -      throw new IOException("IpAddress encoding error, wrong length:  
" +
+         if ( (value.length == 8) && (System.getProperty 
("org.snmp4j.smi.bugCompat.netSnmpIpAddress8Bytes").equals("true")) ) {
+               byte[] tempValue = { 0,0,0,0 };
+               for (int i = 0; i < 4; i++) {
+                 tempValue[i] = value[i];
+               }
+               value = tempValue;
+         } else {
+        throw new IOException("IpAddress encoding error, wrong  
length: " +
                              value.length);
- -    }
+      }
+       }
      inetAddress = InetAddress.getByAddress(value);
    }

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (Darwin)

iD8DBQFHC3syB3953+hexDoRAtQiAJ94YuhWcTjweyvmj9n09iIdLg1xTgCgpbRG
74W33kqmEKg6jHzwI72pHWM=
=qoKB
-----END PGP SIGNATURE-----



More information about the SNMP4J mailing list