File net-snmp-5.7.1-properly-clean-up-old-requests-in-subagents.patch of Package net-snmp

commit 13952f6bee9f408867ab6d2fdfdde4f284074957
Author: Jan Safranek <jsafranek@users.sourceforge.net>
Date:   Wed Oct 26 14:05:16 2011 +0200

    CHANGES: snmplib: from Siddhesh Poyarekar: properly clean up old requests in a subagent when we reconnect to master.
    
    An snmp subagent linked against net-snmp-libs may crash if it handles a
    response which has magic referring to an older disconnected main session. This
    may happen when the subagent
    attempts to clean up old requests on reconnection of the disconnected master
    session.

Index: net-snmp-5.7.1/agent/mibgroup/agentx/subagent.c
===================================================================
--- net-snmp-5.7.1.orig/agent/mibgroup/agentx/subagent.c
+++ net-snmp-5.7.1/agent/mibgroup/agentx/subagent.c
@@ -484,6 +484,26 @@ handle_agentx_packet(int operation, nets
     return 1;
 }
 
+static int
+_invalid_op_and_magic(int op, ns_subagent_magic *smagic)
+{
+    int invalid = 0;
+
+    if (smagic && (snmp_sess_pointer(smagic->session) == NULL ||
+        op == NETSNMP_CALLBACK_OP_TIMED_OUT)) {
+        if (smagic->ovars != NULL) {
+            snmp_free_varbind(smagic->ovars);
+        }
+        free(smagic);
+        invalid = 1;
+    }
+
+    if (op != NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE || smagic == NULL)
+        invalid = 1;
+
+    return invalid;
+}
+
 int
 handle_subagent_response(int op, netsnmp_session * session, int reqid,
                          netsnmp_pdu *pdu, void *magic)
@@ -492,13 +512,7 @@ handle_subagent_response(int op, netsnmp
     netsnmp_variable_list *u = NULL, *v = NULL;
     int             rc = 0;
 
-    if (op != NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE || magic == NULL) {
-        if (op == NETSNMP_CALLBACK_OP_TIMED_OUT && magic != NULL) {
-            if (smagic->ovars != NULL) {
-                snmp_free_varbind(smagic->ovars);
-            }
-            free(smagic);
-        }
+    if (_invalid_op_and_magic(op, magic)) {
         return 1;
     }
 
openSUSE Build Service is sponsored by