Procházet zdrojové kódy

update-alternatives: fix off-by-one errors

alternative_sort_choices() and alternative_sort_slaves() were affected
by an off-by-one error that could result in linked lists looping over
themselves since the last element was not properly put back in the list.
Raphaël Hertzog před 16 roky
rodič
revize
867edc4d17
2 změnil soubory, kde provedl 9 přidání a 4 odebrání
  1. 7 0
      debian/changelog
  2. 2 4
      utils/update-alternatives.c

+ 7 - 0
debian/changelog

@@ -1,3 +1,10 @@
+dpkg (1.15.8.1) UNRELEASED; urgency=low
+
+  * Fix off-by-one error in update-alternatives that lead to an infinite loop
+    while writing the administrative file. Closes: #590854
+
+ -- Raphaël Hertzog <hertzog@debian.org>  Thu, 29 Jul 2010 20:32:33 +0200
+
 dpkg (1.15.8) unstable; urgency=low
 dpkg (1.15.8) unstable; urgency=low
 
 
   [ Raphaël Hertzog ]
   [ Raphaël Hertzog ]

+ 2 - 4
utils/update-alternatives.c

@@ -772,10 +772,8 @@ alternative_sort_choices(struct alternative *a)
 	/* Rewrite the linked list from the sorted table */
 	/* Rewrite the linked list from the sorted table */
 	a->choices = fs = table[0];
 	a->choices = fs = table[0];
 	table[count - 1]->next = NULL;
 	table[count - 1]->next = NULL;
-	for (i = 1; i < count - 1; i++) {
+	for (i = 1; i < count; fs = fs->next, i++)
 		fs->next = table[i];
 		fs->next = table[i];
-		fs = fs->next;
-	}
 	free(table);
 	free(table);
 }
 }
 
 
@@ -800,7 +798,7 @@ alternative_sort_slaves(struct alternative *a)
 	/* Rewrite the linked list from the sorted table */
 	/* Rewrite the linked list from the sorted table */
 	a->slaves = sl = table[0];
 	a->slaves = sl = table[0];
 	table[count - 1]->next = NULL;
 	table[count - 1]->next = NULL;
-	for (i = 1; i < count - 1; sl = sl->next, i++)
+	for (i = 1; i < count; sl = sl->next, i++)
 		sl->next = table[i];
 		sl->next = table[i];
 	free(table);
 	free(table);
 }
 }