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

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