Quellcode durchsuchen

update-alternatives: do not allow to reuse a slave link in another slave alternative

update-alternatives erroneously allowed to reuse a link in another slave
alternative. Given the parsing code already catched this error, it would
immediately result in update-alternatives being unusable to manipulate the
broken alternative.

Reported-by: Andreas Beckmann <debian@abeckmann.de>
Raphaël Hertzog vor 15 Jahren
Ursprung
Commit
638e259f69
3 geänderte Dateien mit 19 neuen und 1 gelöschten Zeilen
  1. 2 0
      debian/changelog
  2. 6 1
      utils/t/100_update_alternatives.t
  3. 11 0
      utils/update-alternatives.c

+ 2 - 0
debian/changelog

@@ -54,6 +54,8 @@ dpkg (1.16.1) UNRELEASED; urgency=low
     directives.
   * dpkg-buildflags(1): make it clear that DEB_*_(SET|APPEND) environment
     variables are meant for users and should not be used by packages.
+  * update-alternatives: do not allow to reuse a slave link in another
+    slave alternative. Closes: #631547
 
   [ Guillem Jover ]
   * Install deb-src-control(5) man pages in dpkg-dev. Closes: #620520

+ 6 - 1
utils/t/100_update_alternatives.t

@@ -81,7 +81,7 @@ my @choices = (
 );
 my $nb_slaves = 4;
 plan tests => (4 * ($nb_slaves + 1) + 2) * 25 # number of check_choices
-		+ 69;			      # rest
+		+ 70;			      # rest
 
 sub cleanup {
     system("rm -rf $tmpdir && mkdir -p $admindir && mkdir -p $altdir");
@@ -385,6 +385,11 @@ call_ua(["--install", "$bindir/slave1", "testmaster", "/bin/date", "10"],
 call_ua(["--install", "$bindir/testmaster", "testmaster", "/bin/date", "10",
 	 "--slave", "$bindir/generic-test", "testslave", "/bin/true" ],
 	expect_failure => 1, to_file => "/dev/null", error_to_file => "/dev/null");
+# try to reuse slave link in another slave alternative of another choice of
+# the same main alternative
+call_ua(["--install", $main_link, $main_name, "/bin/date", "10",
+	 "--slave", "$bindir/slave1", "testslave", "/bin/true" ],
+	expect_failure => 1, to_file => "/dev/null", error_to_file => "/dev/null");
 # lack of absolute filenames in links or file path, non-existing path,
 call_ua(["--install", "../testmaster", "testmaster", "/bin/date", "10"],
         expect_failure => 1, to_file => "/dev/null", error_to_file => "/dev/null");

+ 11 - 0
utils/update-alternatives.c

@@ -2280,6 +2280,17 @@ main(int argc, char **argv)
 				        "managed by %s."), sl->link,
 				      found->master_name);
 			}
+			if (found) {
+				struct slave_link *sl2;
+				for (sl2 = found->slaves; sl2; sl2 = sl2->next)
+					if (strcmp(sl2->link, sl->link) == 0)
+						break;
+				if (sl2 && strcmp(sl2->name, sl->name) != 0)
+					error(_("alternative link %s is already "
+					        "managed by %s (slave of %s)."),
+					      sl->link, sl2->name,
+					      found->master_name);
+			}
 
 			if (sl->link[0] != '/')
 				error(_("alternative link is not absolute as "