snmpsim icon indicating copy to clipboard operation
snmpsim copied to clipboard

snmpsim 0.4.4 error variation module crashes sim UnboundLocalError local variable 'varBinds' referenced before assignment

Open buzz3791 opened this issue 6 years ago • 1 comments

I'm trying to use snmpsim version 0.4.4 to simulate SNMP Error Responses using the Error Variation Module. I'm developing an SNMP Manager and need to test "out of range" error handling for RFC1592 https://tools.ietf.org/html/rfc1592, Section 3.3.6, Table 18 " SNMP ERROR values for a RESPONSE error code". We're monitoring a SNMP agent device that sometimes returns an "out of range" value of 99 instead of 0 through 18.

I'm currently trying to use the error module but I'm encountering what looks like a defect in snmmpsim when using the error module. snmpsim is crashing with this error

File "C:\Python36-32\Scripts\snmpsimd.py", line 1007, in commandResponderCbFun;    pMod.apiPDU.setVarBinds(rspPDU, varBinds);
UnboundLocalError: local variable 'varBinds' referenced before assignment;

Here are the details of what is happening. My .snmprec file contains this single line

1.3.6.1.2.1.2.2.1.6.1|4:error|status=genError

I'm starting the simulator with a command-line like

snmpsimd.py --v2c-arch --data-dir=C:\dev\snmptest\data --agent-udpv4-endpoint=127.0.0.1:1024 --variation-modules-dir=c:\Python36-32\snmpsim\variation

I'm attempting a simple SNMP GET using SNMP Research's brassd utility getone version 18.1.0.20

getone -v2c -port 1024 127.0.0.1 error 1.3.6.1.2.1.2.2.1.6.1

This request crashes snmpsim with this traceback

Process terminated
Traceback (most recent call last):;
  File "c:\python36-32\lib\site-packages\pysnmp\carrier\asyncore\dispatch.py", line 46, in runDispatcher;    use_poll=True, map=self.__sockMap, count=1);
  File "c:\python36-32\lib\asyncore.py", line 207, in loop;    poll_fun(timeout, map);
  File "c:\python36-32\lib\asyncore.py", line 150, in poll;    read(obj);
  File "c:\python36-32\lib\asyncore.py", line 87, in read;    obj.handle_error();
  File "c:\python36-32\lib\asyncore.py", line 83, in read;    obj.handle_read_event();
  File "c:\python36-32\lib\asyncore.py", line 423, in handle_read_event;    self.handle_read();
  File "c:\python36-32\lib\site-packages\pysnmp\carrier\asyncore\dgram\base.py", line 163, in handle_read;    self._cbFun(self, transportAddress, incomingMessage);
  File "c:\python36-32\lib\site-packages\pysnmp\carrier\base.py", line 70, in _cbFun;    self, transportDomain, transportAddress, incomingMessage;
  File "C:\Python36-32\Scripts\snmpsimd.py", line 1007, in commandResponderCbFun;    pMod.apiPDU.setVarBinds(rspPDU, varBinds);
UnboundLocalError: local variable 'varBinds' referenced before assignment;
;During handling of the above exception, another exception occurred:;;
Traceback (most recent call last):;
  File "C:\Python36-32\Scripts\snmpsimd.py", line 1436, in <module>;    transportDispatcher.runDispatcher();
  File "c:\python36-32\lib\site-packages\pysnmp\carrier\asyncore\dispatch.py", line 50, in runDispatcher;    raise PySnmpError('poll error: %s' % ';'.join(format_exception(*exc_info())));
pysnmp.error.PySnmpError: poll error: Traceback (most recent call last):;;  File "c:\python36-32\lib\site-packages\pysnmp\carrier\asyncore\dispatch.py", line 46, in runDispatcher;    use_poll=True, map=self.__sockMap, count=1);;  File "c:\python36-32\lib\asyncore.py", line 207, in loop;    poll_fun(timeout, map);;  File "c:\python36-32\lib\asyncore.py", line 150, in poll;    read(obj);;  File "c:\python36-32\lib\asyncore.py", line 87, in read;    obj.handle_error();;  File "c:\python36-32\lib\asyncore.py", line 83, in read;    obj.handle_read_event();;  File "c:\python36-32\lib\asyncore.py", line 423, in handle_read_event;    self.handle_read();;  File "c:\python36-32\lib\site-packages\pysnmp\carrier\asyncore\dgram\base.py", line 163, in handle_read;    self._cbFun(self, transportAddress, incomingMessage);;  File "c:\python36-32\lib\site-packages\pysnmp\carrier\base.py", line 70, in _cbFun;    self, transportDomain, transportAddress, incomingMessage;;  File "C:\Python36-32\Scripts\snmpsimd.py", line 1007, in commandResponderCbFun;    pMod.apiPDU.setVarBinds(rspPDU, varBinds);;UnboundLocalError: local variable 'varBinds' referenced before assignment;;

buzz3791 avatar Jul 19 '18 14:07 buzz3791

This issue looks similar to this 2013 defect https://sourceforge.net/p/snmpsim/bugs/1/

buzz3791 avatar Jul 19 '18 14:07 buzz3791