Closed y-iwata-bl closed 1 week ago
It took us a while to validate this and confirm the results you provided.
Can you create a pull request so that we can merge your fix?
Thank you for validating my fix.
Sure, I can do that. Please wait a while for me to make the request.
By the way, I have found additional similar potential issues as follows. I would like to include the additional fixes in the request as well. Is that okay?
diff -r pysnmp/proto/mpmod/rfc3412.py /usr/local/lib/python3.9/site-packages/pysnmp/proto/mpmod/rfc3412.py
402a403,406
> if securityModel in snmpEngine.securityModels:
> smHandler = snmpEngine.securityModels[securityModel]
> smHandler.releaseStateInformation(securityStateReference)
>
511a516,518
> if securityModel in snmpEngine.securityModels:
> smHandler = snmpEngine.securityModels[securityModel]
> smHandler.releaseStateInformation(securityStateReference)
diff -r pysnmp/proto/secmod/rfc3414/service.py /usr/local/lib/python3.9/site-packages/pysnmp/proto/secmod/rfc3414/service.py
999a1000
> self._cache.pop(securityStateReference)
1024a1026
> self._cache.pop(securityStateReference)
1105a1108
> self._cache.pop(securityStateReference)
1206a1210
> self._cache.pop(securityStateReference)
1297a1302
> self._cache.pop(securityStateReference)
1368a1374
> self._cache.pop(securityStateReference)
1377a1384
> self._cache.pop(securityStateReference)
1382a1390
> self._cache.pop(securityStateReference)
1445a1454
> self._cache.pop(securityStateReference)
1452a1462
> self._cache.pop(securityStateReference)
Sure. Please feel free to include all changes you suggest. We will review them all together.
Fixed in #143. Further conversation will go on there.
Expected behavior
I expect the cache will be popped as follows.
Actual behavior
My snmp trap receiver using pysnmp library received a SNMPv3 trap message having invalid password for authentication without the reportableFalg. The cache for securityStateReference was not popped properly and the memory of the trap receiver was getting increased.
Following is my analysis of the behavior.
prepareDataElement() in proto/mpmod/rfc3412.py calls processIncomingMsg() in proto/secmod/rfc3414/service.py. processIncomingMsg() pushes a cache to create a message to report later.
And then, the authenticationFailure exception raises because of the invalid password.
prepareDataElement() calls returnResponsePdu() in proto/rfc3412.py to report the error to the sender of the trap. returnResponsePdu() calls prepareResponseMessage() in proto/mpmod/rfc3412.py. prepareResponseMessage() is terminated at the following location without sending the message to report because the reportableFlag is 0.
So, nobody pops the securityStateReference chache, the cache will be accumulated and the memory of the trap receiver will be increased.
Detailed steps
Following is the detailed steps.
Note: The problem does not happen under the following conditions.
Python package information
pysnmp 6.2.4
Operating system information
Red Hat Enterprise Linux release 9.2
Python information
python 3.9
(Optional) Contents of your test script
Relevant log output