Blame SOURCES/iproute2-3.10.0-Fix-multiple-programming-errors.patch

a4b897
From 453eee90927d1c28951af40c3fd2c40365b07055 Mon Sep 17 00:00:00 2001
a4b897
From: Stephen Hemminger <shemming@brocade.com>
a4b897
Date: Wed, 12 Aug 2015 08:35:54 -0700
a4b897
Subject: [PATCH] Fix multiple programming errors
a4b897
MIME-Version: 1.0
a4b897
Content-Type: text/plain; charset=UTF-8
a4b897
Content-Transfer-Encoding: 8bit
a4b897
a4b897
This is a combination of 8 commits:
a4b897
a4b897
commit 2f29d6bb5089271988a820d1f9596f9973ee2e4d
a4b897
Author: Stephen Hemminger <shemming@brocade.com>
a4b897
Date:   Wed Aug 12 08:35:54 2015 -0700
a4b897
a4b897
    ipnetns: make net namespace cache variable size
a4b897
a4b897
    Save some space by using variable size for nsid cache elements.
a4b897
a4b897
    Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
a4b897
a4b897
commit e0dce0e5dc363b7e307984706c130f6ee769259b
a4b897
Author: Phil Sutter <phil@nwl.cc>
a4b897
Date:   Thu Aug 6 14:24:32 2015 +0200
a4b897
a4b897
    misc/ss: avoid NULL pointer dereference
a4b897
a4b897
    This was working before, but only if realloc a) succeeded and b) did not
a4b897
    move the buffer to a different location. ''**buf = **new_buf' then
a4b897
    writes the value of *new_buf's first field into that of *buf.
a4b897
a4b897
    Signed-off-by: Phil Sutter <phil@nwl.cc>
a4b897
a4b897
commit 532ca40a52d4103816f2e50690a02e9dd6c1abe5
a4b897
Author: Phil Sutter <phil@nwl.cc>
a4b897
Date:   Thu Aug 6 14:24:33 2015 +0200
a4b897
a4b897
    misc/ss: simplify buffer realloc, fix checking realloc failure
a4b897
a4b897
    Signed-off-by: Phil Sutter <phil@nwl.cc>
a4b897
a4b897
commit b95d28c380c945ac760b128403dc82279cb9cc39
a4b897
Author: Phil Sutter <phil@nwl.cc>
a4b897
Date:   Thu Aug 6 14:24:34 2015 +0200
a4b897
a4b897
    misc/ss: add missing fclose() calls
a4b897
a4b897
    Signed-off-by: Phil Sutter <phil@nwl.cc>
a4b897
a4b897
commit 5950ba914e12b9c942e45e2dda6b1732a3efa058
a4b897
Author: Phil Sutter <phil@nwl.cc>
a4b897
Date:   Thu Aug 6 14:24:35 2015 +0200
a4b897
a4b897
    lib/namespace: don't leak fd in error case
a4b897
a4b897
    Signed-off-by: Phil Sutter <phil@nwl.cc>
a4b897
a4b897
commit a02371fb3831c8d3d9d53209f2389b250a1fb804
a4b897
Author: Phil Sutter <phil@nwl.cc>
a4b897
Date:   Thu Aug 6 14:24:36 2015 +0200
a4b897
a4b897
    misc/ss: fix memory leak in user_ent_hash_build()
a4b897
a4b897
    Signed-off-by: Phil Sutter <phil@nwl.cc>
a4b897
a4b897
commit 9e5ba07f491037f51472915477575d3e3fe0adcb
a4b897
Author: Phil Sutter <phil@nwl.cc>
a4b897
Date:   Tue Aug 18 18:11:08 2015 +0200
a4b897
a4b897
    lib/namespace: fix fd leakage in non-error case
a4b897
a4b897
    My previous patch 5950ba9 ("lib/namespace: don't leak fd in error case")
a4b897
    was a step in the wrong direction. Instead of closing the opened file
a4b897
    descriptor in error case only, follow a better approach here and close
a4b897
    the fd as soon as it is not used anymore. This way the inelegant goto
a4b897
    statements can be dropped, and the fd leak in non-error case is fixed as
a4b897
    well.
a4b897
a4b897
    Fixes: 5950ba9 ("lib/namespace: don't leak fd in error case")
a4b897
    Signed-off-by: Phil Sutter <phil@nwl.cc>
a4b897
a4b897
commit b765eda924363caec99b760d8cff815ecf4a8de6
a4b897
Author: Nicolas Dichtel <nicolas.dichtel@6wind.com>
a4b897
Date:   Wed Apr 22 10:27:06 2015 +0200
a4b897
a4b897
    libnamespaces: fix warning about syscall()
a4b897
a4b897
    The warning was:
a4b897
    In file included from namespace.c:14:0:
a4b897
    ../include/namespace.h: In function ‘setns’:
a4b897
    ../include/namespace.h:37:2: warning: implicit declaration of function ‘syscall’ [-Wimplicit-function-declaration]
a4b897
a4b897
    Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
a4b897
---
a4b897
 include/namespace.h |  1 +
a4b897
 ip/ipnetns.c        |  6 +++---
a4b897
 lib/namespace.c     |  2 ++
a4b897
 misc/ss.c           | 17 +++++++++++------
a4b897
 4 files changed, 17 insertions(+), 9 deletions(-)
a4b897
a4b897
diff --git a/include/namespace.h b/include/namespace.h
a4b897
index a2ac7dc..5add9d2 100644
a4b897
--- a/include/namespace.h
a4b897
+++ b/include/namespace.h
a4b897
@@ -3,6 +3,7 @@
a4b897
 
a4b897
 #include <sched.h>
a4b897
 #include <sys/mount.h>
a4b897
+#include <unistd.h>
a4b897
 #include <sys/syscall.h>
a4b897
 #include <errno.h>
a4b897
 
a4b897
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
a4b897
index 019f954..00b6cc4 100644
a4b897
--- a/ip/ipnetns.c
a4b897
+++ b/ip/ipnetns.c
a4b897
@@ -140,7 +140,7 @@ struct nsid_cache {
a4b897
 	struct hlist_node	nsid_hash;
a4b897
 	struct hlist_node	name_hash;
a4b897
 	int			nsid;
a4b897
-	char			name[NAME_MAX];
a4b897
+	char			name[0];
a4b897
 };
a4b897
 
a4b897
 #define NSIDMAP_SIZE		128
a4b897
@@ -165,7 +165,7 @@ static struct nsid_cache *netns_map_get_by_nsid(int nsid)
a4b897
 	return NULL;
a4b897
 }
a4b897
 
a4b897
-static int netns_map_add(int nsid, char *name)
a4b897
+static int netns_map_add(int nsid, const char *name)
a4b897
 {
a4b897
 	struct nsid_cache *c;
a4b897
 	uint32_t h;
a4b897
@@ -173,7 +173,7 @@ static int netns_map_add(int nsid, char *name)
a4b897
 	if (netns_map_get_by_nsid(nsid) != NULL)
a4b897
 		return -EEXIST;
a4b897
 
a4b897
-	c = malloc(sizeof(*c));
a4b897
+	c = malloc(sizeof(*c) + strlen(name));
a4b897
 	if (c == NULL) {
a4b897
 		perror("malloc");
a4b897
 		return -ENOMEM;
a4b897
diff --git a/lib/namespace.c b/lib/namespace.c
a4b897
index c03a103..0549916 100644
a4b897
--- a/lib/namespace.c
a4b897
+++ b/lib/namespace.c
a4b897
@@ -57,8 +57,10 @@ int netns_switch(char *name)
a4b897
 	if (setns(netns, CLONE_NEWNET) < 0) {
a4b897
 		fprintf(stderr, "setting the network namespace \"%s\" failed: %s\n",
a4b897
 			name, strerror(errno));
a4b897
+		close(netns);
a4b897
 		return -1;
a4b897
 	}
a4b897
+	close(netns);
a4b897
 
a4b897
 	if (unshare(CLONE_NEWNS) < 0) {
a4b897
 		fprintf(stderr, "unshare failed: %s\n", strerror(errno));
a4b897
diff --git a/misc/ss.c b/misc/ss.c
a4b897
index 951e1eb..5d0cc36 100644
a4b897
--- a/misc/ss.c
a4b897
+++ b/misc/ss.c
a4b897
@@ -474,8 +474,10 @@ static void user_ent_hash_build(void)
a4b897
 
a4b897
 		sprintf(name + nameoff, "%d/fd/", pid);
a4b897
 		pos = strlen(name);
a4b897
-		if ((dir1 = opendir(name)) == NULL)
a4b897
+		if ((dir1 = opendir(name)) == NULL) {
a4b897
+			free(pid_context);
a4b897
 			continue;
a4b897
+		}
a4b897
 
a4b897
 		process[0] = '\0';
a4b897
 		p = process;
a4b897
@@ -541,7 +543,7 @@ static int find_entry(unsigned ino, char **buf, int type)
a4b897
 	struct user_ent *p;
a4b897
 	int cnt = 0;
a4b897
 	char *ptr;
a4b897
-	char **new_buf = buf;
a4b897
+	char *new_buf;
a4b897
 	int len, new_buf_len;
a4b897
 	int buf_used = 0;
a4b897
 	int buf_len = 0;
a4b897
@@ -583,12 +585,12 @@ static int find_entry(unsigned ino, char **buf, int type)
a4b897
 
a4b897
 			if (len < 0 || len >= buf_len - buf_used) {
a4b897
 				new_buf_len = buf_len + ENTRY_BUF_SIZE;
a4b897
-				*new_buf = realloc(*buf, new_buf_len);
a4b897
+				new_buf = realloc(*buf, new_buf_len);
a4b897
 				if (!new_buf) {
a4b897
 					fprintf(stderr, "ss: failed to malloc buffer\n");
a4b897
 					abort();
a4b897
 				}
a4b897
-				**buf = **new_buf;
a4b897
+				*buf = new_buf;
a4b897
 				buf_len = new_buf_len;
a4b897
 				continue;
a4b897
 			} else {
a4b897
@@ -2928,6 +2930,7 @@ static int packet_show_line(char *buf, const struct filter *f, int fam)
a4b897
 static int packet_show(struct filter *f)
a4b897
 {
a4b897
 	FILE *fp;
a4b897
+	int rc = 0;
a4b897
 
a4b897
 	if (!filter_af_get(f, AF_PACKET) || !(f->states & (1 << SS_CLOSE)))
a4b897
 		return 0;
a4b897
@@ -2939,9 +2942,10 @@ static int packet_show(struct filter *f)
a4b897
 	if ((fp = net_packet_open()) == NULL)
a4b897
 		return -1;
a4b897
 	if (generic_record_read(fp, packet_show_line, f, AF_PACKET))
a4b897
-		return -1;
a4b897
+		rc = -1;
a4b897
 
a4b897
-	return 0;
a4b897
+	fclose(fp);
a4b897
+	return rc;
a4b897
 }
a4b897
 
a4b897
 static int netlink_show_one(struct filter *f,
a4b897
@@ -3118,6 +3122,7 @@ static int netlink_show(struct filter *f)
a4b897
 		netlink_show_one(f, prot, pid, groups, 0, 0, 0, rq, wq, sk, cb);
a4b897
 	}
a4b897
 
a4b897
+	fclose(fp);
a4b897
 	return 0;
a4b897
 }
a4b897
 
a4b897
-- 
a4b897
1.8.3.1
a4b897