Patrick Williams | ddad1a1 | 2017-02-23 20:36:32 -0600 | [diff] [blame] | 1 | Description: fix snmpd crash via AgentX connection |
| 2 | |
| 3 | taken from Fedora, net-snmp-5.7-agentx-crash.patch |
| 4 | |
| 5 | bz729738 - net-snmp dumps core in netsnmp_oid_find_prefix |
| 6 | bz1038011 - net-snmp: snmpd crashes/hangs when AgentX subagent times-out |
| 7 | |
| 8 | commit f9304c83f76202db0e684269ca1af32e43cd9db4 |
| 9 | Author: Jan Safranek <jsafranek@users.sourceforge.net> |
| 10 | Date: Tue Feb 7 14:53:44 2012 +0100 |
| 11 | |
| 12 | CHANGES: PATCH 1633670: fixed snmpd crashing when an AgentX subagent |
| 13 | disconnect in the middle of processing of a request. |
| 14 | |
| 15 | I fixed also the memory leak reported in the tracker comments. |
| 16 | |
| 17 | Upstream-Status: Backport |
| 18 | |
| 19 | Signed-off-by: Zhu Yanjun <yanjun.zhu@windriver.com> |
| 20 | Signed-off-by: Jackie Huang <jackie.huang@windriver.com> |
| 21 | |
| 22 | --- |
| 23 | agent/mibgroup/agentx/master.c | 5 +++++ |
| 24 | agent/mibgroup/agentx/master_admin.c | 9 +++++++-- |
| 25 | 2 files changed, 12 insertions(+), 2 deletions(-) |
| 26 | |
| 27 | diff --git a/agent/mibgroup/agentx/master.c b/agent/mibgroup/agentx/master.c |
| 28 | index c42a42a..baeebaf 100644 |
| 29 | --- a/agent/mibgroup/agentx/master.c |
| 30 | +++ b/agent/mibgroup/agentx/master.c |
| 31 | @@ -219,6 +219,9 @@ agentx_got_response(int operation, |
| 32 | if (!cache) { |
| 33 | DEBUGMSGTL(("agentx/master", "response too late on session %8p\n", |
| 34 | session)); |
| 35 | + /* response is too late, free the cache */ |
| 36 | + if (magic) |
| 37 | + netsnmp_free_delegated_cache((netsnmp_delegated_cache*) magic); |
| 38 | return 0; |
| 39 | } |
| 40 | requests = cache->requests; |
| 41 | @@ -606,6 +609,8 @@ agentx_master_handler(netsnmp_mib_handler *handler, |
| 42 | result = snmp_async_send(ax_session, pdu, agentx_got_response, cb_data); |
| 43 | if (result == 0) { |
| 44 | snmp_free_pdu(pdu); |
| 45 | + if (cb_data) |
| 46 | + netsnmp_free_delegated_cache((netsnmp_delegated_cache*) cb_data); |
| 47 | } |
| 48 | |
| 49 | return SNMP_ERR_NOERROR; |
| 50 | diff --git a/agent/mibgroup/agentx/master_admin.c b/agent/mibgroup/agentx/master_admin.c |
| 51 | index f16f392..b84b85e 100644 |
| 52 | --- a/agent/mibgroup/agentx/master_admin.c |
| 53 | +++ b/agent/mibgroup/agentx/master_admin.c |
| 54 | @@ -133,11 +133,16 @@ close_agentx_session(netsnmp_session * session, int sessid) |
| 55 | * requests, so that the delegated request will be completed and |
| 56 | * further requests can be processed |
| 57 | */ |
| 58 | - netsnmp_remove_delegated_requests_for_session(session); |
| 59 | + while (netsnmp_remove_delegated_requests_for_session(session)) { |
| 60 | + DEBUGMSGTL(("agentx/master", "Continue removing delegated reqests\n")); |
| 61 | + } |
| 62 | + |
| 63 | if (session->subsession != NULL) { |
| 64 | netsnmp_session *subsession = session->subsession; |
| 65 | for(; subsession; subsession = subsession->next) { |
| 66 | - netsnmp_remove_delegated_requests_for_session(subsession); |
| 67 | + while (netsnmp_remove_delegated_requests_for_session(subsession)) { |
| 68 | + DEBUGMSGTL(("agentx/master", "Continue removing delegated subsession reqests\n")); |
| 69 | + } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | -- |
| 74 | 2.7.4 |
| 75 | |