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