Skip to content

Commit

Permalink
Fix TRAP PDU proxy translation
Browse files Browse the repository at this point in the history
Fixed crash on uninitialized component serialization left out in
SNMP v1 TRAP PDU to SNMPv2/3 TRAP PDU translation routine.
  • Loading branch information
etingof committed Jul 19, 2019
1 parent d75f2fd commit 0228371
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Revision 4.4.10, released 2019-04-XX
- Fixed `var-bindings` initialization to prevent pyasn1 encoder failures
with newer pyasn1 versions where `SequenceOf` type looses its default
initializer.
- Fixed crash on uninitialized component serialization left out in
SNMP v1 TRAP PDU to SNMPv2/3 TRAP PDU proxy translation routine.

Revision 4.4.9, released 2019-02-09
-----------------------------------
Expand Down
24 changes: 12 additions & 12 deletions pysnmp/proto/proxy/rfc2576.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,29 +142,29 @@ def v1ToV2(v1Pdu, origV2Pdu=None, snmpTrapCommunity=''):
(oid, __v1ToV2ValueMap[v1Val.tagSet].clone(v1Val))
)

if pduType in rfc3411.responseClassPDUs:
# 4.1.2.2.1&2
if pduType not in rfc3411.notificationClassPDUs:
errorStatus = int(v1.apiPDU.getErrorStatus(v1Pdu))
errorIndex = int(v1.apiPDU.getErrorIndex(v1Pdu, muteErrors=True))
if errorStatus == 2: # noSuchName
if origV2Pdu.tagSet == v2c.GetNextRequestPDU.tagSet:
v2VarBinds = [(o, rfc1905.endOfMibView) for o, v in v2VarBinds]
else:
v2VarBinds = [(o, rfc1905.noSuchObject) for o, v in v2VarBinds]

if pduType in rfc3411.responseClassPDUs:
# 4.1.2.2.1&2
if errorStatus == 2: # noSuchName
if origV2Pdu.tagSet == v2c.GetNextRequestPDU.tagSet:
v2VarBinds = [(o, rfc1905.endOfMibView) for o, v in v2VarBinds]
else:
v2VarBinds = [(o, rfc1905.noSuchObject) for o, v in v2VarBinds]

# partial one-to-one mapping - 4.2.1
v2c.apiPDU.setErrorStatus(v2Pdu, errorStatus)
v2c.apiPDU.setErrorIndex(v2Pdu, errorIndex)

# 4.1.2.1 --> no-op

elif pduType in rfc3411.confirmedClassPDUs:
v2c.apiPDU.setErrorStatus(v2Pdu, 0)
v2c.apiPDU.setErrorIndex(v2Pdu, 0)

if pduType not in rfc3411.notificationClassPDUs:
v2c.apiPDU.setRequestID(v2Pdu, int(v1.apiPDU.getRequestID(v1Pdu)))

else:
v2c.apiPDU.setDefaults(v2Pdu)

v2c.apiPDU.setVarBinds(v2Pdu, v2VarBinds)

debug.logger & debug.flagPrx and debug.logger('v1ToV2: v2Pdu %s' % v2Pdu.prettyPrint())
Expand Down

0 comments on commit 0228371

Please sign in to comment.