[debhelper-devel] [debhelper] 02/02: dh_systemd_*: Properly quote unit names in autoscripts

Niels Thykier nthykier at moszumanska.debian.org
Tue Oct 10 18:08:31 UTC 2017


This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch master
in repository debhelper.

commit bb17a1df1734b7216379d2205697a9947e9252f9
Author: Niels Thykier <niels at thykier.net>
Date:   Tue Oct 10 18:07:31 2017 +0000

    dh_systemd_*: Properly quote unit names in autoscripts
    
    Signed-off-by: Niels Thykier <niels at thykier.net>
---
 debian/changelog                 |  4 ++++
 dh_systemd_enable                |  8 ++++++--
 dh_systemd_start                 |  4 +++-
 t/dh_installsystemd/dh_systemd.t | 16 ++++++++++++----
 4 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index e4ca937..8224de4 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -34,6 +34,10 @@ debhelper (10.9.1) UNRELEASED; urgency=medium
     and continuing.
   * t: Add tests for dh_systemd_* based on WIP tests from Felipe
     Sateler related to a new dh_installsystemd helper.
+  * dh_systemd_enable: Properly quote unit names to preserve
+    escaped names like "\x2d".  Thanks to Bernd Zeimetz for
+    reporting the issue.  (Closes: #764730)
+  * dh_systemd_start: Ditto.
 
   [ Dmitry Shachnev ]
   * qmake.pm: Add basic cross-building support.  (Closes: #877357)
diff --git a/dh_systemd_enable b/dh_systemd_enable
index bcb5272..ef91ef2 100755
--- a/dh_systemd_enable
+++ b/dh_systemd_enable
@@ -239,9 +239,13 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 
 	next if @units == 0;
 
-	my $unitargs = join(" ", sort map { basename($_) } @units);
+	# Wrap the basenames in '' to preserve \x2d when the shell parses the
+	# name.  (#764730)
+	my $unitargs = join(' ', sort map { q{'} . basename($_) . q{'}  } @units);
 	for my $unit (sort @units) {
-		my $base = basename($unit);
+		# Wrap the basenames in '' to preserve \x2d when the shell parses the
+		# name.  (#764730)
+		my $base = q{'} . basename($unit) . q{'};
 		if ($dh{NO_ENABLE}) {
 			autoscript($package, 'postinst', 'postinst-systemd-dont-enable', { 'UNITFILE' => $base });
 		} else {
diff --git a/dh_systemd_start b/dh_systemd_start
index d17bb28..8e2b777 100755
--- a/dh_systemd_start
+++ b/dh_systemd_start
@@ -213,11 +213,13 @@ foreach my $package (@{$dh{DOPACKAGES}}) {
 
 	next if @units == 0;
 
+	# Wrap the basenames in '' to preserve \x2d when the shell parses the
+	# name.  (#764730)
+	my $unitargs = join(' ', sort map { q{'} . basename($_) . q{'} } @units);
 	# The $package and $sed parameters are always the same.
 	# This wrapper function makes the following logic easier to read.
 	my $sd_autoscript = sub {
 		my ($script, $filename) = @_;
-		my $unitargs = join(" ", sort map { basename($_) } @units);
 		autoscript($package, $script, $filename, { 'UNITFILES' => $unitargs });
 	};
 
diff --git a/t/dh_installsystemd/dh_systemd.t b/t/dh_installsystemd/dh_systemd.t
index 265e84c..dee7096 100755
--- a/t/dh_installsystemd/dh_systemd.t
+++ b/t/dh_installsystemd/dh_systemd.t
@@ -27,10 +27,10 @@ sub unit_is_enabled {
 	my $matches;
 	$num_masks = $num_masks // $num_enables;
 	@output=`cat debian/$package.postinst.debhelper`;
-	$matches = grep { m{^if deb-systemd-helper .* was-enabled .*$unit\.service} } @output;
+	$matches = grep { m{^if deb-systemd-helper .* was-enabled .*'\Q$unit\E\.service'} } @output;
 	ok($matches == $num_enables) or diag("$unit appears to have been enabled $matches times (expected $num_enables)");
 	@output=`cat debian/$package.postrm.debhelper`;
-	$matches = grep { m{deb-systemd-helper mask.*$unit\.service} } @output;
+	$matches = grep { m{deb-systemd-helper mask.*'\Q$unit\E\.service'} } @output;
 	ok($matches == $num_masks) or diag("$unit appears to have been masked $matches times (expected $num_masks)");
 }
 sub unit_is_started {
@@ -39,10 +39,10 @@ sub unit_is_started {
 	my $matches;
 	$num_stops = $num_stops // $num_starts;
 	@output=`cat debian/$package.postinst.debhelper`;
-	$matches = grep { m{deb-systemd-invoke \$_dh_action .*$unit.service} } @output;
+	$matches = grep { m{deb-systemd-invoke \$_dh_action .*'\Q$unit\E.service'} } @output;
 	ok($matches == $num_starts) or diag("$unit appears to have been started $matches times (expected $num_starts)");
 	@output=`cat debian/$package.prerm.debhelper`;
-	$matches = grep { m{deb-systemd-invoke stop .*$unit.service} } @output;
+	$matches = grep { m{deb-systemd-invoke stop .*'\Q$unit\E.service'} } @output;
 	ok($matches == $num_stops) or diag("$unit appears to have been stopped $matches times (expected $num_stops)");
 }
 
@@ -115,6 +115,14 @@ each_compat_up_to_and_incl_subtest(10, sub {
 	ok($matches == 1);
 	ok(run_dh_tool('dh_clean'));
 
+	# Quoting #764730
+	make_path('debian/foo/lib/systemd/system/');
+	install_file('debian/foo.service', 'debian/foo/lib/systemd/system/foo\x2dfuse.service');
+	ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_enable'));
+	ok(run_dh_tool({ 'needs_root' => 1 }, 'dh_systemd_start'));
+	unit_is_enabled('foo', 'foo\x2dfuse', 1);
+	unit_is_started('foo', 'foo\x2dfuse', 1);
+	ok(run_dh_tool('dh_clean'));
 });
 
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debhelper/debhelper.git




More information about the debhelper-devel mailing list