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

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