]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util: Fix assertion in split() on missing '
authorMartin Pitt <martin.pitt@ubuntu.com>
Wed, 22 Apr 2015 22:09:43 +0000 (23:09 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 22 Apr 2015 23:14:07 +0000 (01:14 +0200)
When parsing a unit with a trailing slash after an escaped line break, like

  ExecStart=/bin/echo 'foo \
    bar'

the split() function (through config_parse()) asserted and crashed pid 1:

  Assertion 'current[*l + 1] == quotechars[0]' failed at ../src/shared/util.c:583, function split(). Aborting.

Fix this by returning an error in this case ("trailing garbage").

Add corresponding test case. Also fix the missing "unit" argument of
config_parse_exec() in the comment.

https://launchpad.net/bugs/1447243

src/shared/util.c
src/test/test-unit-file.c

index 4a044840bd40f636a49bfc24edc5ffbda08d3ca6..6a883d79d12b6704f5d8cb7a56546af385fce8f3 100644 (file)
@@ -570,13 +570,12 @@ const char* split(const char **state, size_t *l, const char *separator, bool quo
                 char quotechars[2] = {*current, '\0'};
 
                 *l = strcspn_escaped(current + 1, quotechars);
-                if (current[*l + 1] == '\0' ||
+                if (current[*l + 1] == '\0' || current[*l + 1] != quotechars[0] ||
                     (current[*l + 2] && !strchr(separator, current[*l + 2]))) {
                         /* right quote missing or garbage at the end */
                         *state = current;
                         return NULL;
                 }
-                assert(current[*l + 1] == quotechars[0]);
                 *state = current++ + *l + 2;
         } else if (quoted) {
                 *l = strcspn_escaped(current, separator);
index 22ac76de564b15ae49e0a989ba143a81031ee2ff..5a9796df583aa6f5a077121a90a74b4b4b747b3d 100644 (file)
@@ -91,6 +91,7 @@ static void check_execcommand(ExecCommand *c,
 
 static void test_config_parse_exec(void) {
         /* int config_parse_exec(
+                 const char *unit,
                  const char *filename,
                  unsigned line,
                  const char *section,
@@ -302,6 +303,20 @@ static void test_config_parse_exec(void) {
         assert_se(r == 0);
         assert_se(c1->command_next == NULL);
 
+        log_info("/* missing ending ' */");
+        r = config_parse_exec(NULL, "fake", 4, "section", 1,
+                              "LValue", 0, "/path 'foo",
+                              &c, NULL);
+        assert_se(r == 0);
+        assert_se(c1->command_next == NULL);
+
+        log_info("/* missing ending ' with trailing backslash */");
+        r = config_parse_exec(NULL, "fake", 4, "section", 1,
+                              "LValue", 0, "/path 'foo\\",
+                              &c, NULL);
+        assert_se(r == 0);
+        assert_se(c1->command_next == NULL);
+
         exec_command_free_list(c);
 }