snmplib/snmp_api: Remove the request on the session when the sending is failed
snmpd is terminated abnormally due to an invalid memory access after
the sending of a request is failed.
The time out callback for the failed request is executed when the
session is closing because the request remains in the internal session.
The cleanup for the request is executed on the
callback(NETSNMP_CALLBACK_OP_SEND_FAILED,) and also on the time out
callback(NETSNMP_CALLBACK_OP_TIMED_OUT,), so the wrong memory access
happens.
Remove the failed request from the internal session after the callback
for the failed request is done.
I ran the snmpget loop over 21 thousand times now, no crash. I do observe something similar to a connection reset, though:
("i" is my loop counter)
i=21234
Error in packet
Reason: (noSuchName) There is no such variable name in this MIB.
Failed object: iso.3.6.1.4.1.8072.9999.9999.3.0
And the agentx module shows:
2023-07-28 20:27:04,503 - pyagentx.network - ERROR - Network error, master disconnect?!
But it reconnects just fine.
I tried the same loop in jammy, and observed the same behavior: this disconnect, and recovery. Maybe it's something in the python module, or the way it was implemented. After all, it's a demo.
I found another two patches that fix the latest crash:
commit 408c8919e36feb4 e9c1024e74d3b8c 77454d89a0
Author: Bart Van Assche <email address hidden>
Date: Sun Apr 14 18:57:17 2019 -0700
snmplib: Introduce the function remove_request()
This patch does not change any functionality.
and this one which uses the new function:
commit d6689d6a938e29e 02f1964bc7d7a15 103817c0fa
Author: Masayoshi Mizuma <email address hidden>
Date: Mon Apr 8 19:56:04 2019 -0400
snmplib/ snmp_api: Remove the request on the session when the sending is failed
snmpd is terminated abnormally due to an invalid memory access after
the sending of a request is failed.
The time out callback for the failed request is executed when the NETSNMP_ CALLBACK_ OP_SEND_ FAILED, ) and also on the time out NETSNMP_ CALLBACK_ OP_TIMED_ OUT,), so the wrong memory access
session is closing because the request remains in the internal session.
The cleanup for the request is executed on the
callback(
callback(
happens.
Remove the failed request from the internal session after the callback
for the failed request is done.
Signed-off-by: Masayoshi Mizuma <email address hidden>
Reported-by: Shogo Matsumoto <email address hidden>
I ran the snmpget loop over 21 thousand times now, no crash. I do observe something similar to a connection reset, though:
("i" is my loop counter) 1.4.1.8072. 9999.9999. 3.0
i=21234
Error in packet
Reason: (noSuchName) There is no such variable name in this MIB.
Failed object: iso.3.6.
And the agentx module shows:
2023-07-28 20:27:04,503 - pyagentx.network - ERROR - Network error, master disconnect?!
But it reconnects just fine.
I tried the same loop in jammy, and observed the same behavior: this disconnect, and recovery. Maybe it's something in the python module, or the way it was implemented. After all, it's a demo.
I'll upload this new package to the ppa.