File net-snmp-5.7.3-fix-subagent-data-corruption.patch of Package net-snmp.22257

From 9201c9479ffa78033aaff6ccf5f4f1a34a33791e Mon Sep 17 00:00:00 2001
From: Bart Van Assche <bvanassche@acm.org>
Date: Tue, 15 Oct 2019 20:27:57 -0700
Subject: [PATCH] agent: Improve robustness of handle_subagent_set_response()

Several users have reported that 'retsess' can be NULL. Avoid that the
agent crashes if retsess == NULL. See also:
* https://sourceforge.net/p/net-snmp/mailman/message/29293701/
* https://sourceforge.net/p/net-snmp/bugs/2468/
* https://github.com/net-snmp/net-snmp/issues/28
---
 agent/mibgroup/agentx/subagent.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/agent/mibgroup/agentx/subagent.c b/agent/mibgroup/agentx/subagent.c
index ffd1eb549..20ea0d989 100644
--- a/agent/mibgroup/agentx/subagent.c
+++ b/agent/mibgroup/agentx/subagent.c
@@ -675,11 +675,13 @@ handle_subagent_set_response(int op, netsnmp_session * session, int reqid,
         pdu->variables = NULL;  /* the variables were added by us */
     }
 
-    netsnmp_assert(retsess != NULL);
-    pdu->command = AGENTX_MSG_RESPONSE;
-    pdu->version = retsess->version;
+    if (retsess && pdu) {
+        pdu->command = AGENTX_MSG_RESPONSE;
+        pdu->version = retsess->version;
 
-    if (!snmp_send(retsess, pdu)) {
+        if (!snmp_send(retsess, pdu))
+            snmp_free_pdu(pdu);
+    } else if (pdu) {
         snmp_free_pdu(pdu);
     }
     DEBUGMSGTL(("agentx/subagent", "  FINISHED\n"));
openSUSE Build Service is sponsored by