Blame SOURCES/0040-RH-bindings-fix.patch

671555
---
671555
 libmultipath/alias.c |   39 ++++++++++++++++++++++++++++++---------
671555
 1 file changed, 30 insertions(+), 9 deletions(-)
671555
671555
Index: multipath-tools-130222/libmultipath/alias.c
671555
===================================================================
671555
--- multipath-tools-130222.orig/libmultipath/alias.c
671555
+++ multipath-tools-130222/libmultipath/alias.c
671555
@@ -46,11 +46,11 @@ format_devname(char *name, int id, int l
671555
 	memset(name,0, len);
671555
 	strcpy(name, prefix);
671555
 	for (pos = len - 1; pos >= prefix_len; pos--) {
671555
+		id--;
671555
 		name[pos] = 'a' + id % 26;
671555
 		if (id < 26)
671555
 			break;
671555
 		id /= 26;
671555
-		id--;
671555
 	}
671555
 	memmove(name + prefix_len, name + pos, len - pos);
671555
 	name[prefix_len + len - pos] = '\0';
671555
@@ -66,13 +66,22 @@ scan_devname(char *alias, char *prefix)
671555
 	if (!prefix || strncmp(alias, prefix, strlen(prefix)))
671555
 		return -1;
671555
 
671555
+	if (strlen(alias) == strlen(prefix))
671555
+		return -1;	
671555
+
671555
+	if (strlen(alias) > strlen(prefix) + 7)
671555
+		/* id of 'aaaaaaaa' overflows int */
671555
+		return -1;
671555
+
671555
 	c = alias + strlen(prefix);
671555
 	while (*c != '\0' && *c != ' ' && *c != '\t') {
671555
+		if (*c < 'a' || *c > 'z')
671555
+			return -1;
671555
 		i = *c - 'a';
671555
 		n = ( n * 26 ) + i;
671555
+		if (n < 0)
671555
+			return -1;
671555
 		c++;
671555
-		if (*c < 'a' || *c > 'z')
671555
-			break;
671555
 		n++;
671555
 	}
671555
 
671555
@@ -84,7 +93,9 @@ lookup_binding(FILE *f, char *map_wwid,
671555
 {
671555
 	char buf[LINE_MAX];
671555
 	unsigned int line_nr = 0;
671555
-	int id = 0;
671555
+	int id = 1;
671555
+	int biggest_id = 1;
671555
+	int smallest_bigger_id = INT_MAX;
671555
 
671555
 	*map_alias = NULL;
671555
 
671555
@@ -100,8 +111,12 @@ lookup_binding(FILE *f, char *map_wwid,
671555
 		if (!alias) /* blank line */
671555
 			continue;
671555
 		curr_id = scan_devname(alias, prefix);
671555
-		if (curr_id >= id)
671555
-			id = curr_id + 1;
671555
+		if (curr_id == id)
671555
+			id++;
671555
+		if (curr_id > biggest_id)
671555
+			biggest_id = curr_id;
671555
+		if (curr_id > id && curr_id < smallest_bigger_id)
671555
+			smallest_bigger_id = curr_id;
671555
 		wwid = strtok(NULL, " \t");
671555
 		if (!wwid){
671555
 			condlog(3,
671555
@@ -116,11 +131,17 @@ lookup_binding(FILE *f, char *map_wwid,
671555
 			if (*map_alias == NULL)
671555
 				condlog(0, "Cannot copy alias from bindings "
671555
 					"file : %s", strerror(errno));
671555
-			return id;
671555
+			return 0;
671555
 		}
671555
 	}
671555
 	condlog(3, "No matching wwid [%s] in bindings file.", map_wwid);
671555
-	return id;
671555
+	if (id < 0) {
671555
+		condlog(0, "no more available user_friendly_names");
671555
+		return 0;
671555
+	}
671555
+	if (id < smallest_bigger_id)
671555
+		return id;
671555
+	return biggest_id + 1;
671555
 }
671555
 
671555
 static int
671555
@@ -254,7 +275,7 @@ get_user_friendly_alias(char *wwid, char
671555
 		return NULL;
671555
 	}
671555
 
671555
-	if (!alias && can_write && !bindings_read_only)
671555
+	if (!alias && can_write && !bindings_read_only && id)
671555
 		alias = allocate_binding(fd, wwid, id, prefix);
671555
 
671555
 	fclose(f);