Blame SOURCES/net-snmp-5.7.2-extend-reload.patch

b5ae06
1228893 - snmpd segfaults on reload with multiple 'exec' entry
b5ae06
b5ae06
commit 54290bede338164ca65a3eed224fa5040d7dd857
b5ae06
Author: Niels Baggesen <nba@users.sourceforge.net>
b5ae06
Date:   Fri Oct 26 07:50:11 2012 +0200
b5ae06
b5ae06
    Better cleanup of "exec" config to avoid crash during reload of config
b5ae06
b5ae06
diff --git a/agent/mibgroup/agent/extend.c b/agent/mibgroup/agent/extend.c
b5ae06
index 68a11e2..9cb641c 100644
b5ae06
--- a/agent/mibgroup/agent/extend.c
b5ae06
+++ b/agent/mibgroup/agent/extend.c
b5ae06
@@ -34,7 +34,7 @@ typedef struct extend_registration_block_s {
b5ae06
     size_t              oid_len;
b5ae06
     long                num_entries;
b5ae06
     netsnmp_extend     *ehead;
b5ae06
-    netsnmp_handler_registration       *reg[3];
b5ae06
+    netsnmp_handler_registration       *reg[4];
b5ae06
     struct extend_registration_block_s *next;
b5ae06
 } extend_registration_block;
b5ae06
 extend_registration_block *ereg_head = NULL;
b5ae06
@@ -222,10 +222,13 @@ _register_extend( oid *base, size_t len )
b5ae06
     rc = netsnmp_register_watched_scalar2( reg, winfo );
b5ae06
     if (rc != SNMPERR_SUCCESS)
b5ae06
         goto bail;
b5ae06
+    eptr->reg[3] = reg;
b5ae06
 
b5ae06
     return eptr;
b5ae06
 
b5ae06
 bail:
b5ae06
+    if (eptr->reg[3])
b5ae06
+        netsnmp_unregister_handler(eptr->reg[3]);
b5ae06
     if (eptr->reg[2])
b5ae06
         netsnmp_unregister_handler(eptr->reg[2]);
b5ae06
     if (eptr->reg[1])
b5ae06
@@ -267,6 +270,7 @@ extend_clear_callback(int majorID, int minorID,
b5ae06
         netsnmp_unregister_handler( eptr->reg[0] );
b5ae06
         netsnmp_unregister_handler( eptr->reg[1] );
b5ae06
         netsnmp_unregister_handler( eptr->reg[2] );
b5ae06
+        netsnmp_unregister_handler( eptr->reg[3] );
b5ae06
         SNMP_FREE(eptr);
b5ae06
     }
b5ae06
     ereg_head = NULL;
b5ae06
@@ -550,6 +554,10 @@ extend_parse_config(const char *token, char *cptr)
b5ae06
     }
b5ae06
 
b5ae06
     eptr      = _register_extend( oid_buf, oid_len );
b5ae06
+    if (!eptr) {
b5ae06
+        snmp_log(LOG_ERR, "Failed to register extend entry '%s' - possibly duplicate name.\n", exec_name );
b5ae06
+        return;
b5ae06
+    }
b5ae06
     extension = _new_extension( exec_name, flags, eptr );
b5ae06
     if (extension) {
b5ae06
         extension->command  = strdup( exec_command );