Blob Blame History Raw
From 0433c9062acfa62b663126485581e22d49a029e2 Mon Sep 17 00:00:00 2001
From: Phil Cameron <pcameron@redhat.com>
Date: Fri, 15 Apr 2016 13:35:41 -0400
Subject: [PATCH]     fix segfault in adding interface

    bugzilla 1283773

    Signed-off-by: Phil Cameron <pcameron@redhat.com>
---
 ...tionptr-properly-allocate-newly-created-i.patch | 63 ++++++++++++++++++++++
 iptraf-ng.spec                                     |  7 ++-
 2 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 0003-bugfix-positionptr-properly-allocate-newly-created-i.patch

diff --git a/0003-bugfix-positionptr-properly-allocate-newly-created-i.patch b/0003-bugfix-positionptr-properly-allocate-newly-created-i.patch
new file mode 100644
index 0000000..a850458
--- /dev/null
+++ b/0003-bugfix-positionptr-properly-allocate-newly-created-i.patch
@@ -0,0 +1,63 @@
+From 690663d07f29789c1ba2260e59c4f71b8721dea6 Mon Sep 17 00:00:00 2001
+From: Vitezslav Samel <vitezslav@samel.cz>
+Date: Thu, 17 Apr 2014 14:24:23 +0200
+Subject: [PATCH 001/111] bugfix: positionptr(): properly allocate newly
+ created interfaces
+
+When creating new entry in interface list (for interface created when
+ifstats() already running) we must allocate/init the rate too.
+
+Fix this bug by creating new function alloc_iflist_entry() and use it
+where appropriate.
+
+Signed-off-by: Vitezslav Samel <vitezslav@samel.cz>
+Signed-off-by: Nikola Pajkovsky <n.pajkovsky@gmail.com>
+---
+ src/ifstats.c | 16 ++++++++++++----
+ 1 file changed, 12 insertions(+), 4 deletions(-)
+
+diff --git a/src/ifstats.c b/src/ifstats.c
+index 2eb51b6..2a5bba4 100644
+--- a/src/ifstats.c
++++ b/src/ifstats.c
+@@ -126,6 +126,15 @@ static int ifinlist(struct iflist *list, char *ifname)
+ 	return result;
+ }
+ 
++static struct iflist *alloc_iflist_entry(void)
++{
++	struct iflist *tmp = xmallocz(sizeof(struct iflist));
++
++	rate_alloc(&tmp->rate, 5);
++
++	return tmp;
++}
++
+ /*
+  * Initialize the list of interfaces.  This linked list is used in the
+  * selection boxes as well as in the general interface statistics screen.
+@@ -171,10 +180,9 @@ static void initiflist(struct iflist **list)
+ 		 * At this point, the interface is now sure to be up and running.
+ 		 */
+ 
+-		struct iflist *itmp = xmallocz(sizeof(struct iflist));
+-		strcpy(itmp->ifname, ifname);
++		struct iflist *itmp = alloc_iflist_entry();
+ 		itmp->ifindex = ifindex;
+-		rate_alloc(&itmp->rate, 5);
++		strcpy(itmp->ifname, ifname);
+ 
+ 		/* make the linked list sorted by ifindex */
+ 		struct iflist *cur = *list, *last = NULL;
+@@ -211,7 +219,7 @@ static struct iflist *positionptr(struct iflist *iflist, const int ifindex)
+ 	}
+ 	/* no interface was found, try to create new one */
+ 	if (ptmp == NULL) {
+-		struct iflist *itmp = xmallocz(sizeof(struct iflist));
++		struct iflist *itmp = alloc_iflist_entry();
+ 		itmp->ifindex = ifindex;
+ 		itmp->index = last->index + 1;
+ 		int r = dev_get_ifname(ifindex, itmp->ifname);
+-- 
+2.5.5
+