Version 5.7.1
When trying to implement the TUTORIAL-MIB in a subagent using nstAgentSubagentObject.c, as part of following "TUT:Writing a Subagent", I found that set operations on the Integer object were failing with 'wrongLength'. This was on an x86_64 Linux system.
Part of the mailing list thread is below with final responses from Robert Story. The apparent fix is to change netsnmp_register_int_instance() to be netsnmp_register_long_instance(). Which apparently makes this a bug against the Tutorial Wiki more than anything else.
-------------------
JL> On 2/24/12 10:59 AM, Joe Lorenz wrote:
JL> > $ snmpset -v 2c -c private dut
JL> > NET-SNMP-TUTORIAL-MIB::nstAgentSubagentObject.0 i 5 Error in packet.
JL> > Reason: wrongLength (The set value has an illegal length from what the
JL> > agent expects)
JL> > Failed object: NET-SNMP-TUTORIAL-MIB::nstAgentSubagentObject.0
JL> >
JL> > This is on an x86_64 environment where sizeof(int) = 4 and sizeof(long)
JL> > = 8. What I'm noticing is that netsnmp_register_int_instance() calls
JL> > netsnmp_create_watcher_info() with sizeof(int). But I also see
JL> > snmp_set_var_typed_integer() call snmp_set_var_value() with
JL> > sizeof(long), which seems possibly inconsistent.
JL> >
JL> > The snmp_set_var_value() appears to have conditionals for differences
JL> > between size of int and long. So I'm not sure why this doesn't Just
JL> > Work.
Because when snmp_set_var_value is called to create the internal structure to
hold the incoming value, is saves a length of 8 for ANY integer, regardless of
the actual incoming size.
JL> > I think I will attempt to change netsnmp_register_int_instance() and see
JL> > what happens.
a better idea would be to change the subagent to use
netsnmp_register_long_instance.
JL> > If anyone has insight on this, I'm all ears.
It's a bug. The integer instance handler should properly deal with the fact
that the variable structure uses a long, and properly convert it down to a
integer. Can you submit a bug report?
On Fri,
JL> > 24 Feb 2012 11:32:13 -0500 Joe wrote:
JL> I changed netsnmp_register_int() to use sizeof(long) instead of
JL> sizeof(int), and now sets are working.
JL>
JL> Now how do I know I'm not causing any regressions with such a change? :-/
You are. Essentially, you are telling the code it's ok to write up to 8 bytes,
when the pointer passed in for storage is pointing to only 4 bytes of storage.
Thanks for the report. I've fixed this in the relevant code file in the web tutorial aread (though it may take a while for this to become live)