summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pitt <martin.pitt@ubuntu.com>2015-04-22 23:09:43 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-04-29 08:55:33 -0400
commite7a90c1117e4d37be191a6567b405d7908a30434 (patch)
tree429561f5ec70d96ff36470ef97075ca451e88258
parenta8d917c7e49e3111aaf7bd80cd1b8731c4ea81ed (diff)
util: Fix assertion in split() on missing '
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 (cherry picked from commit 470dca63cd2b1579f45f72b6b9777494abeff105)
-rw-r--r--src/shared/util.c3
-rw-r--r--src/test/test-unit-file.c15
2 files changed, 16 insertions, 2 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 1e1bf944f..649344d88 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -571,13 +571,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);
diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c
index e517f571d..9f3e3a227 100644
--- a/src/test/test-unit-file.c
+++ b/src/test/test-unit-file.c
@@ -92,6 +92,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,
@@ -303,6 +304,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);
}