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

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