Skip to content

proto/rfc3412: do not crash for statusInformation without errorIndication - #227

Open
ffourcot wants to merge 1 commit into
lextudio:mainfrom
ffourcot:fix_crash_statusInformation_without_errorIndication
Open

proto/rfc3412: do not crash for statusInformation without errorIndication#227
ffourcot wants to merge 1 commit into
lextudio:mainfrom
ffourcot:fix_crash_statusInformation_without_errorIndication

Conversation

@ffourcot

@ffourcot ffourcot commented Feb 2, 2026

Copy link
Copy Markdown

We have some hardware (Mikrotik RbwAPG-60ad) generating crashes with pysnmp. Full traceback is:

ERROR default_exception_handler(): Exception in callback AbstractTransportDispatcher._callback_function()
handle: <Handle AbstractTransportDispatcher._callback_function()>
 Traceback (most recent call last):
   File "pysnmp/proto/rfc3412.py", line 425, in receive_message
     ) = mpHandler.prepare_data_elements(
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
         snmpEngine, transportDomain, transportAddress, wholeMsg
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     )  # type: ignore
     ^
   File "pysnmp/proto/mpmod/rfc3412.py", line 905, in prepare_data_elements
     raise statusInformation
  pysnmp.proto.error.StatusInformation: {'sendPduHandle': 5936909}
 During handling of the above exception, another exception occurred:
 Traceback (most recent call last):
   File "asyncio/events.py", line 89, in _run
     self._context.run(self._callback, *self._args)
     ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "pysnmp/carrier/base.py", line 166, in _callback_function
     self.__recv_callables[recvId](
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
         self, transportDomain, transportAddress, incomingMessage
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     )
     ^
   File "pysnmp/entity/engine.py", line 228, in __receive_message_callback
     self.message_dispatcher.receive_message(
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
         self, transportDomain, transportAddress, wholeMsg
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     )
     ^
   File "pysnmp/proto/rfc3412.py", line 442, in receive_message
     self.__expire_request(
     ~~~~~~~~~~~~~~~~~~~~~^
         statusInformation["sendPduHandle"],  # type: ignore
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     ...<2 lines>...
         statusInformation,
         ^^^^^^^^^^^^^^^^^^
     )
     ^
   File "pysnmp/proto/rfc3412.py", line 696, in __expire_request
     processResponsePdu(
     ~~~~~~~~~~~~~~~~~~^
         snmpEngine,
         ^^^^^^^^^^^
     ...<10 lines>...
         cachedParams["cbCtx"],
         ^^^^^^^^^^^^^^^^^^^^^^
     )
     ^
   File "pysnmp/entity/rfc3413/cmdgen.py", line 78, in process_response_pdu
     errorIndication = statusInformation["errorIndication"]
                       ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
   File "pysnmp/proto/error.py", line 44, in __getitem__
     return self.__errorIndication[key]
            ~~~~~~~~~~~~~~~~~~~~~~^^^^^
 KeyError: 'errorIndication'

Packets generating this traceback are class INTERNAL_CLASS_PDUS, without varBinds, and matching rule 7.2.11e from RFC 3412.

Current code is raising a statusInformation without errorIndication, since RFC says:

       e) A SUCCESS result is returned.  SNMPv3 Message Processing is
          complete.

This patch avoid the crash, we don't need to call __expire_request when we receive this kind of packets.

…tion

We have some hardware (Mikrotik RbwAPG-60ad) generating crashes with
pysnmp. Full traceback is:

ERROR default_exception_handler(): Exception in callback AbstractTransportDispatcher._callback_function()
handle: <Handle AbstractTransportDispatcher._callback_function()>
 Traceback (most recent call last):
   File "pysnmp/proto/rfc3412.py", line 425, in receive_message
     ) = mpHandler.prepare_data_elements(
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
         snmpEngine, transportDomain, transportAddress, wholeMsg
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     )  # type: ignore
     ^
   File "pysnmp/proto/mpmod/rfc3412.py", line 905, in prepare_data_elements
     raise statusInformation
  pysnmp.proto.error.StatusInformation: {'sendPduHandle': 5936909}
 During handling of the above exception, another exception occurred:
 Traceback (most recent call last):
   File "asyncio/events.py", line 89, in _run
     self._context.run(self._callback, *self._args)
     ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "pysnmp/carrier/base.py", line 166, in _callback_function
     self.__recv_callables[recvId](
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
         self, transportDomain, transportAddress, incomingMessage
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     )
     ^
   File "pysnmp/entity/engine.py", line 228, in __receive_message_callback
     self.message_dispatcher.receive_message(
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
         self, transportDomain, transportAddress, wholeMsg
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     )
     ^
   File "pysnmp/proto/rfc3412.py", line 442, in receive_message
     self.__expire_request(
     ~~~~~~~~~~~~~~~~~~~~~^
         statusInformation["sendPduHandle"],  # type: ignore
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     ...<2 lines>...
         statusInformation,
         ^^^^^^^^^^^^^^^^^^
     )
     ^
   File "pysnmp/proto/rfc3412.py", line 696, in __expire_request
     processResponsePdu(
     ~~~~~~~~~~~~~~~~~~^
         snmpEngine,
         ^^^^^^^^^^^
     ...<10 lines>...
         cachedParams["cbCtx"],
         ^^^^^^^^^^^^^^^^^^^^^^
     )
     ^
   File "pysnmp/entity/rfc3413/cmdgen.py", line 78, in process_response_pdu
     errorIndication = statusInformation["errorIndication"]
                       ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
   File "pysnmp/proto/error.py", line 44, in __getitem__
     return self.__errorIndication[key]
            ~~~~~~~~~~~~~~~~~~~~~~^^^^^
 KeyError: 'errorIndication'

Packets generating this traceback are class INTERNAL_CLASS_PDUS, without
varBinds, and matching rule 7.2.11e from RFC 3412.

Current code is raising a statusInformation without errorIndication,
since RFC says:

       e) A SUCCESS result is returned.  SNMPv3 Message Processing is
          complete.

This patch avoid the crash, we don't need to call __expire_request when
we receive this kind of packets.
@lextm lextm added more info needed We need more information about this issue priority:low Low priority items. warning:faulty device Issues related to specific network devices are out of scope. labels Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

more info needed We need more information about this issue priority:low Low priority items. warning:faulty device Issues related to specific network devices are out of scope.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants