diff options
author | Raphaël Hertzog <hertzog@debian.org> | 2010-07-29 20:36:09 +0200 |
---|---|---|
committer | Raphaël Hertzog <hertzog@debian.org> | 2010-07-29 20:36:09 +0200 |
commit | 867edc4d1736e0052143d1cd28b7dda3fd71ba45 (patch) | |
tree | d3ad8fb522295dc4830a897035f6b195d0a7bc43 /utils | |
parent | 189dcd07b4cd62159fb0a28db79249d86c91fb1b (diff) | |
download | dpkg-867edc4d1736e0052143d1cd28b7dda3fd71ba45.tar.gz |
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.
Diffstat (limited to 'utils')
-rw-r--r-- | utils/update-alternatives.c | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/utils/update-alternatives.c b/utils/update-alternatives.c index 0f6487a62..52148c350 100644 --- a/utils/update-alternatives.c +++ b/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); } |