anitazha / rpms / systemd

Forked from rpms/systemd 3 years ago
Clone

Blame SOURCES/0179-core-Fix-assertion-with-empty-Exec-paths.patch

803fb7
From 9ea44466541480b583032617e6060313f79a6bda Mon Sep 17 00:00:00 2001
803fb7
From: Martin Pitt <martin.pitt@ubuntu.com>
803fb7
Date: Thu, 14 May 2015 09:06:40 +0200
803fb7
Subject: [PATCH] core: Fix assertion with empty Exec*= paths
803fb7
803fb7
An Exec*= line with whitespace after modifiers, like
803fb7
803fb7
  ExecStart=- /bin/true
803fb7
803fb7
is considered to have an empty command path. This is as specified, but causes
803fb7
systemd to crash with
803fb7
803fb7
  Assertion 'skip < l' failed at ../src/core/load-fragment.c:607, function config_parse_exec(). Aborting.
803fb7
  Aborted (core dumped)
803fb7
803fb7
Fix this by logging an error instead and ignoring the invalid line.
803fb7
803fb7
Add corresponding test cases. Also add a test case for a completely empty value
803fb7
which resets the command list.
803fb7
803fb7
https://launchpad.net/bugs/1454173
803fb7
803fb7
Cherry-picked from: 35b1078e1c375df244e19961792aeb78ca34bb54
803fb7
Resolves: #1222517
803fb7
---
803fb7
 src/core/load-fragment.c  |  6 +++++-
803fb7
 src/test/test-unit-file.c | 21 +++++++++++++++++++++
803fb7
 2 files changed, 26 insertions(+), 1 deletion(-)
803fb7
803fb7
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
803fb7
index f17a82fcd..ec4cf4eef 100644
803fb7
--- a/src/core/load-fragment.c
803fb7
+++ b/src/core/load-fragment.c
803fb7
@@ -604,7 +604,11 @@ int config_parse_exec(const char *unit,
803fb7
                                 skip = separate_argv0 + ignore;
803fb7
 
803fb7
                                 /* skip special chars in the beginning */
803fb7
-                                assert(skip < l);
803fb7
+                                if (l <= skip) {
803fb7
+                                        log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Empty path in command line, ignoring: %s", rvalue);
803fb7
+                                        r = 0;
803fb7
+                                        goto fail;
803fb7
+                                }
803fb7
 
803fb7
                         } else if (strneq(word, ";", MAX(l, 1U)))
803fb7
                                 /* new commandline */
803fb7
diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c
803fb7
index 9f3e3a227..550098332 100644
803fb7
--- a/src/test/test-unit-file.c
803fb7
+++ b/src/test/test-unit-file.c
803fb7
@@ -318,6 +318,27 @@ static void test_config_parse_exec(void) {
803fb7
         assert_se(r == 0);
803fb7
         assert_se(c1->command_next == NULL);
803fb7
 
803fb7
+        log_info("/* invalid space between modifiers */");
803fb7
+        r = config_parse_exec(NULL, "fake", 4, "section", 1,
803fb7
+                              "LValue", 0, "- /path",
803fb7
+                              &c, NULL);
803fb7
+        assert_se(r == 0);
803fb7
+        assert_se(c1->command_next == NULL);
803fb7
+
803fb7
+        log_info("/* only modifiers, no path */");
803fb7
+        r = config_parse_exec(NULL, "fake", 4, "section", 1,
803fb7
+                              "LValue", 0, "-",
803fb7
+                              &c, NULL);
803fb7
+        assert_se(r == 0);
803fb7
+        assert_se(c1->command_next == NULL);
803fb7
+
803fb7
+        log_info("/* empty argument, reset */");
803fb7
+        r = config_parse_exec(NULL, "fake", 4, "section", 1,
803fb7
+                              "LValue", 0, "",
803fb7
+                              &c, NULL);
803fb7
+        assert_se(r == 0);
803fb7
+        assert_se(c == NULL);
803fb7
+
803fb7
         exec_command_free_list(c);
803fb7
 }
803fb7