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

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