Просмотр исходного кода

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 лет назад: 16
Родитель
Сommit
867edc4d17
2 измененных файлов с 9 добавлено и 4 удалено
  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
 
   [ 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 */
 	a->choices = fs = table[0];
 	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 = fs->next;
-	}
 	free(table);
 }
 
@@ -800,7 +798,7 @@ alternative_sort_slaves(struct alternative *a)
 	/* Rewrite the linked list from the sorted table */
 	a->slaves = sl = table[0];
 	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];
 	free(table);
 }