[AGENT++] BER incompatibilty issue in SNMP++

Henning Eggers henning.eggers at plath.de
Tue Mar 16 14:26:36 CET 2004


Hi!
I call this an "issue" (MS-style) because I am not sure if this is actually
against the BERules or if the device in question does not implement them
properly. Here is the issue:

We had a device that did not answer to GET requests from SNMP++ but answered
to others, like MIB-Explorer. I examined the requests and found that the
only difference between them was that certain Length-fields were encoded in
the long style when they could have been encoded in short style (length
smaller than 0x80). After fixing this in SNMP++ the device did answer
properly.

The problem was in asn_build_sequence that always used long type length
encoding (2 bytes) and snmp_build_var_op that assumed that
asn_build_sequence did it this way. The problem here is that encoding a
sequence requires to insert the length of the sequence before it gets
actually calculated. The best way to solve this is to build the sequence in
a temporary buffer, then to encode the sequence header and length (using
asn_build_sequence) and finally to memcpy from the temp buffer behind the
sequence header+length. Most functions using asn_build_sequence do it this
way, except for snmp_build_var_op and snmp_auth_build. I corrected the first
and added a comment to the latter because it calculates the sequence length
beforehand assuming that the community string won't be longer than 0x7f.
That seems to be a fairly safe guess.

As I stated in the beginning I am not sure if a BER implementation is
REQUIRED to always use the shortest encoding possible for the length field
or if the agent should simply accept both styles, no matter if this is
nescessary or not.

I attached a diff-file for the asn1.cpp file from snmp++v3.2.10a that
contains all the changes.

Greetings,
Henning Eggers


-------------- next part --------------
A non-text attachment was scrubbed...
Name: asn1.cpp.diff
Type: application/octet-stream
Size: 5481 bytes
Desc: not available
Url : http://lists.agentpp.org/pipermail/agentpp/attachments/20040316/3066ae7c/attachment.dll 


More information about the AGENTPP mailing list