Blame SOURCES/net-snmp-5.7-agentx-crash.patch

8a419f
729738 - net-snmp dumps core in netsnmp_oid_find_prefix
8a419f
8a419f
commit f9304c83f76202db0e684269ca1af32e43cd9db4
8a419f
Author: Jan Safranek <jsafranek@users.sourceforge.net>
8a419f
Date:   Tue Feb 7 14:53:44 2012 +0100
8a419f
8a419f
    CHANGES: PATCH 1633670: fixed snmpd crashing when an AgentX subagent disconnect in the middle of processing of a request.
8a419f
    
8a419f
    I fixed also the memory leak reported in the tracker comments.
8a419f
8a419f
diff --git a/agent/mibgroup/agentx/master.c b/agent/mibgroup/agentx/master.c
8a419f
index c42a42a..baeebaf 100644
8a419f
--- a/agent/mibgroup/agentx/master.c
8a419f
+++ b/agent/mibgroup/agentx/master.c
8a419f
@@ -219,6 +219,9 @@ agentx_got_response(int operation,
8a419f
     if (!cache) {
8a419f
         DEBUGMSGTL(("agentx/master", "response too late on session %8p\n",
8a419f
                     session));
8a419f
+        /* response is too late, free the cache */
8a419f
+        if (magic)
8a419f
+            netsnmp_free_delegated_cache((netsnmp_delegated_cache*) magic);
8a419f
         return 0;
8a419f
     }
8a419f
     requests = cache->requests;
8a419f
@@ -606,6 +609,8 @@ agentx_master_handler(netsnmp_mib_handler *handler,
8a419f
     result = snmp_async_send(ax_session, pdu, agentx_got_response, cb_data);
8a419f
     if (result == 0) {
8a419f
         snmp_free_pdu(pdu);
8a419f
+        if (cb_data)
8a419f
+            netsnmp_free_delegated_cache((netsnmp_delegated_cache*) cb_data);
8a419f
     }
8a419f
 
8a419f
     return SNMP_ERR_NOERROR;
8a419f
diff --git a/agent/mibgroup/agentx/master_admin.c b/agent/mibgroup/agentx/master_admin.c
8a419f
index f16f392..b84b85e 100644
8a419f
--- a/agent/mibgroup/agentx/master_admin.c
8a419f
+++ b/agent/mibgroup/agentx/master_admin.c
8a419f
@@ -133,11 +133,16 @@ close_agentx_session(netsnmp_session * session, int sessid)
8a419f
          * requests, so that the delegated request will be completed and
8a419f
          * further requests can be processed
8a419f
          */
8a419f
-        netsnmp_remove_delegated_requests_for_session(session);
8a419f
+	while (netsnmp_remove_delegated_requests_for_session(session)) {
8a419f
+		DEBUGMSGTL(("agentx/master", "Continue removing delegated reqests\n"));
8a419f
+	}
8a419f
+
8a419f
         if (session->subsession != NULL) {
8a419f
             netsnmp_session *subsession = session->subsession;
8a419f
             for(; subsession; subsession = subsession->next) {
8a419f
-                netsnmp_remove_delegated_requests_for_session(subsession);
8a419f
+                while (netsnmp_remove_delegated_requests_for_session(subsession)) {
8a419f
+			DEBUGMSGTL(("agentx/master", "Continue removing delegated subsession reqests\n"));
8a419f
+		}
8a419f
             }
8a419f
         }
8a419f