Blame SOURCES/net-snmp-5.5-extend-realloc-leak.patch

b5ae06
978384 - possible memory leak while realocking extend.c:1364
b5ae06
b5ae06
commit 55605ee3452aef5aabe4ed15a83374a97728e64a
b5ae06
Author: Jan Safranek <jsafranek@users.sourceforge.net>
b5ae06
Date:   Wed Jan 9 09:26:56 2013 +0100
b5ae06
b5ae06
    Fixed memory leak on failed realloc.
b5ae06
b5ae06
diff -up net-snmp-5.7.2/agent/mibgroup/agent/extend.c.orig net-snmp-5.7.2/agent/mibgroup/agent/extend.c
b5ae06
--- net-snmp-5.7.2/agent/mibgroup/agent/extend.c.orig	2013-06-26 15:50:15.000000000 +0200
b5ae06
+++ net-snmp-5.7.2/agent/mibgroup/agent/extend.c	2013-06-26 15:55:09.839899740 +0200
b5ae06
@@ -1457,17 +1457,26 @@ handle_nsExtendOutput2Table(netsnmp_mib_
b5ae06
 char * _get_cmdline(netsnmp_extend *extend)
b5ae06
 {
b5ae06
     size_t          size;
b5ae06
+    char           *args = extend->args;
b5ae06
+    char           *newbuf;
b5ae06
+   
b5ae06
+    if (args == NULL)
b5ae06
+        /* Use empty string for processes without arguments. */
b5ae06
+        args = "";
b5ae06
     
b5ae06
     size = strlen(extend->command) + strlen(extend->args) + 2;
b5ae06
     if (size > cmdlinesize) {
b5ae06
-        cmdlinebuf = realloc(cmdlinebuf, size);
b5ae06
-	if (!cmdlinebuf) {
b5ae06
+        newbuf = realloc(cmdlinebuf, size);
b5ae06
+	if (!newbuf) {
b5ae06
+            free(cmdlinebuf);
b5ae06
+            cmdlinebuf = NULL;
b5ae06
             cmdlinesize = 0;
b5ae06
             return NULL;
b5ae06
-	}
b5ae06
-	cmdlinesize = size;
b5ae06
+        }
b5ae06
+        cmdlinesize = size;
b5ae06
+        cmdlinebuf = newbuf;
b5ae06
     }
b5ae06
-    sprintf(cmdlinebuf, "%s %s", extend->command, extend->args);
b5ae06
+    sprintf(cmdlinebuf, "%s %s", extend->command, args);
b5ae06
     return cmdlinebuf;
b5ae06
 }
b5ae06