Blame SOURCES/0120-RHBZ-1043093-realloc-fix.patch

4ae388
---
4ae388
 libmultipath/dmparser.c   |    6 ++++--
4ae388
 libmultipath/regex.c      |    9 ++++++++-
4ae388
 multipath/main.c          |    9 ++++++---
4ae388
 multipathd/cli_handlers.c |   41 ++++++++++++-----------------------------
4ae388
 multipathd/uxlsnr.c       |   13 ++++++++++++-
4ae388
 5 files changed, 42 insertions(+), 36 deletions(-)
4ae388
4ae388
Index: multipath-tools-130222/libmultipath/dmparser.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/dmparser.c
4ae388
+++ multipath-tools-130222/libmultipath/dmparser.c
4ae388
@@ -20,14 +20,16 @@
4ae388
 static int
4ae388
 merge_words (char ** dst, char * word, int space)
4ae388
 {
4ae388
-	char * p;
4ae388
+	char * p = *dst;
4ae388
 	int len;
4ae388
 
4ae388
 	len = strlen(*dst) + strlen(word) + space;
4ae388
 	*dst = REALLOC(*dst, len + 1);
4ae388
 
4ae388
-	if (!*dst)
4ae388
+	if (!*dst) {
4ae388
+		free(p);
4ae388
 		return 1;
4ae388
+	}
4ae388
 
4ae388
 	p = *dst;
4ae388
 
4ae388
Index: multipath-tools-130222/libmultipath/regex.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/libmultipath/regex.c
4ae388
+++ multipath-tools-130222/libmultipath/regex.c
4ae388
@@ -123,7 +123,14 @@ static void init_syntax_once(void)
4ae388
 
4ae388
 /* (Re)Allocate N items of type T using malloc, or fail.  */
4ae388
 #define TALLOC(n, t)	     ((t *) malloc ((n) * sizeof (t)))
4ae388
-#define RETALLOC(addr, n, t) ((addr) = (t *) realloc (addr, (n) * sizeof (t)))
4ae388
+#define RETALLOC(addr, n, t)                                            \
4ae388
+do {                                                                    \
4ae388
+	t *tmp = (t *) realloc (addr, (n) * sizeof (t));                \
4ae388
+	if (!tmp)                                                       \
4ae388
+		free(addr);                                             \
4ae388
+	(addr) = tmp;                                                   \
4ae388
+} while(0)
4ae388
+
4ae388
 #define REGEX_TALLOC(n, t)   ((t *) REGEX_ALLOCATE ((n) * sizeof (t)))
4ae388
 
4ae388
 #define BYTEWIDTH 8		/* In bits.  */
4ae388
Index: multipath-tools-130222/multipath/main.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/multipath/main.c
4ae388
+++ multipath-tools-130222/multipath/main.c
4ae388
@@ -394,7 +394,7 @@ out:
4ae388
 static int
4ae388
 dump_config (void)
4ae388
 {
4ae388
-	char * c;
4ae388
+	char * c, * tmp = NULL;
4ae388
 	char * reply;
4ae388
 	unsigned int maxlen = 256;
4ae388
 	int again = 1;
4ae388
@@ -402,9 +402,12 @@ dump_config (void)
4ae388
 	reply = MALLOC(maxlen);
4ae388
 
4ae388
 	while (again) {
4ae388
-		if (!reply)
4ae388
+		if (!reply) {
4ae388
+			if (tmp)
4ae388
+				free(tmp);
4ae388
 			return 1;
4ae388
-		c = reply;
4ae388
+		}
4ae388
+		c = tmp = reply;
4ae388
 		c += snprint_defaults(c, reply + maxlen - c);
4ae388
 		again = ((c - reply) == maxlen);
4ae388
 		if (again) {
4ae388
Index: multipath-tools-130222/multipathd/cli_handlers.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/multipathd/cli_handlers.c
4ae388
+++ multipath-tools-130222/multipathd/cli_handlers.c
4ae388
@@ -26,11 +26,14 @@
4ae388
 #define REALLOC_REPLY(r, a, m)					\
4ae388
 	do {							\
4ae388
 		if ((a)) {					\
4ae388
+			char *tmp = (r);			\
4ae388
 			(r) = REALLOC((r), (m) * 2);		\
4ae388
 			if ((r)) {				\
4ae388
 				memset((r) + (m), 0, (m));	\
4ae388
 				(m) *= 2;			\
4ae388
 			}					\
4ae388
+			else					\
4ae388
+				free(tmp);			\
4ae388
 		}						\
4ae388
 	} while (0)
4ae388
 
4ae388
@@ -144,7 +147,7 @@ show_config (char ** r, int * len)
4ae388
 	unsigned int maxlen = INITIAL_REPLY_LEN;
4ae388
 	int again = 1;
4ae388
 
4ae388
-	reply = MALLOC(maxlen);
4ae388
+	c = reply = MALLOC(maxlen);
4ae388
 
4ae388
 	while (again) {
4ae388
 		if (!reply)
4ae388
@@ -152,44 +155,24 @@ show_config (char ** r, int * len)
4ae388
 		c = reply;
4ae388
 		c += snprint_defaults(c, reply + maxlen - c);
4ae388
 		again = ((c - reply) == maxlen);
4ae388
-		if (again) {
4ae388
-			reply = REALLOC(reply, maxlen * 2);
4ae388
-			if (!reply)
4ae388
-				return 1;
4ae388
-			memset(reply + maxlen, 0, maxlen);
4ae388
-			maxlen *= 2;
4ae388
+		REALLOC_REPLY(reply, again, maxlen);
4ae388
+		if (again)
4ae388
 			continue;
4ae388
-		}
4ae388
 		c += snprint_blacklist(c, reply + maxlen - c);
4ae388
 		again = ((c - reply) == maxlen);
4ae388
-		if (again) {
4ae388
-			reply = REALLOC(reply, maxlen * 2);
4ae388
-			if (!reply)
4ae388
-				return 1;
4ae388
-			memset(reply + maxlen, 0, maxlen);
4ae388
-			maxlen *= 2;
4ae388
+		REALLOC_REPLY(reply, again, maxlen);
4ae388
+		if (again)
4ae388
 			continue;
4ae388
-		}
4ae388
 		c += snprint_blacklist_except(c, reply + maxlen - c);
4ae388
 		again = ((c - reply) == maxlen);
4ae388
-		if (again) {
4ae388
-			reply = REALLOC(reply, maxlen * 2);
4ae388
-			if (!reply)
4ae388
-				return 1;
4ae388
-			memset(reply + maxlen, 0, maxlen);
4ae388
-			maxlen *= 2;
4ae388
+		REALLOC_REPLY(reply, again, maxlen);
4ae388
+		if (again)
4ae388
 			continue;
4ae388
-		}
4ae388
 		c += snprint_hwtable(c, reply + maxlen - c, conf->hwtable);
4ae388
 		again = ((c - reply) == maxlen);
4ae388
-		if (again) {
4ae388
-			reply = REALLOC(reply, maxlen * 2);
4ae388
-			if (!reply)
4ae388
-				return 1;
4ae388
-			memset(reply + maxlen, 0, maxlen);
4ae388
-			maxlen *= 2;
4ae388
+		REALLOC_REPLY(reply, again, maxlen);
4ae388
+		if (again)
4ae388
 			continue;
4ae388
-		}
4ae388
 		c += snprint_mptable(c, reply + maxlen - c, conf->mptable);
4ae388
 		again = ((c - reply) == maxlen);
4ae388
 		REALLOC_REPLY(reply, again, maxlen);
4ae388
Index: multipath-tools-130222/multipathd/uxlsnr.c
4ae388
===================================================================
4ae388
--- multipath-tools-130222.orig/multipathd/uxlsnr.c
4ae388
+++ multipath-tools-130222/multipathd/uxlsnr.c
4ae388
@@ -64,6 +64,10 @@ static void new_client(int ux_sock)
4ae388
 
4ae388
 	/* put it in our linked list */
4ae388
 	c = (struct client *)MALLOC(sizeof(*c));
4ae388
+	if (!c) {
4ae388
+		close(fd);
4ae388
+		return;
4ae388
+	}
4ae388
 	memset(c, 0, sizeof(*c));
4ae388
 	c->fd = fd;
4ae388
 	c->next = clients;
4ae388
@@ -124,11 +128,18 @@ void * uxsock_listen(int (*uxsock_trigge
4ae388
 	sigdelset(&mask, SIGHUP);
4ae388
 	sigdelset(&mask, SIGUSR1);
4ae388
 	while (1) {
4ae388
+		struct pollfd *tmp;
4ae388
 		struct client *c;
4ae388
 		int i, poll_count;
4ae388
 
4ae388
 		/* setup for a poll */
4ae388
-		polls = REALLOC(polls, (1+num_clients) * sizeof(*polls));
4ae388
+		tmp = REALLOC(polls, (1+num_clients) * sizeof(*polls));
4ae388
+		/* If we can't allocate poliing space for the new client,
4ae388
+		 * close it */
4ae388
+		if (!tmp)
4ae388
+			dead_client(clients);
4ae388
+		else
4ae388
+			polls = tmp;
4ae388
 		polls[0].fd = ux_sock;
4ae388
 		polls[0].events = POLLIN;
4ae388