]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: Fix assertion with empty Exec*= paths
authorMartin Pitt <martin.pitt@ubuntu.com>
Thu, 14 May 2015 07:06:40 +0000 (09:06 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 15 May 2015 18:02:44 +0000 (20:02 +0200)
An Exec*= line with whitespace after modifiers, like

  ExecStart=- /bin/true

is considered to have an empty command path. This is as specified, but causes
systemd to crash with

  Assertion 'skip < l' failed at ../src/core/load-fragment.c:607, function config_parse_exec(). Aborting.
  Aborted (core dumped)

Fix this by logging an error instead and ignoring the invalid line.

Add corresponding test cases. Also add a test case for a completely empty value
which resets the command list.

https://launchpad.net/bugs/1454173

src/core/load-fragment.c
src/test/test-unit-file.c

index 33d9e2714accdb2a67673d986f9d0c7a74640e9d..3865017d971a8b4bfa92de02b171bd278d8d0829 100644 (file)
@@ -595,7 +595,11 @@ int config_parse_exec(
                                 skip = separate_argv0 + ignore;
 
                                 /* skip special chars in the beginning */
-                                assert(skip < l);
+                                if (l <= skip) {
+                                        log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Empty path in command line, ignoring: %s", rvalue);
+                                        r = 0;
+                                        goto fail;
+                                }
 
                         } else if (strneq(word, ";", MAX(l, 1U)))
                                 /* new commandline */
index f3f6c29f75deefcf32f553128896d80af1206ae3..03ca70a493bbc776c70dfbb45d0bf6f52fc7fcb5 100644 (file)
@@ -317,6 +317,27 @@ static void test_config_parse_exec(void) {
         assert_se(r == 0);
         assert_se(c1->command_next == NULL);
 
+        log_info("/* invalid space between modifiers */");
+        r = config_parse_exec(NULL, "fake", 4, "section", 1,
+                              "LValue", 0, "- /path",
+                              &c, NULL);
+        assert_se(r == 0);
+        assert_se(c1->command_next == NULL);
+
+        log_info("/* only modifiers, no path */");
+        r = config_parse_exec(NULL, "fake", 4, "section", 1,
+                              "LValue", 0, "-",
+                              &c, NULL);
+        assert_se(r == 0);
+        assert_se(c1->command_next == NULL);
+
+        log_info("/* empty argument, reset */");
+        r = config_parse_exec(NULL, "fake", 4, "section", 1,
+                              "LValue", 0, "",
+                              &c, NULL);
+        assert_se(r == 0);
+        assert_se(c == NULL);
+
         exec_command_free_list(c);
 }