You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
3.0 KiB
78 lines
3.0 KiB
From 9ea44466541480b583032617e6060313f79a6bda Mon Sep 17 00:00:00 2001 |
|
From: Martin Pitt <martin.pitt@ubuntu.com> |
|
Date: Thu, 14 May 2015 09:06:40 +0200 |
|
Subject: [PATCH] core: Fix assertion with empty Exec*= paths |
|
|
|
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 |
|
|
|
Cherry-picked from: 35b1078e1c375df244e19961792aeb78ca34bb54 |
|
Resolves: #1222517 |
|
--- |
|
src/core/load-fragment.c | 6 +++++- |
|
src/test/test-unit-file.c | 21 +++++++++++++++++++++ |
|
2 files changed, 26 insertions(+), 1 deletion(-) |
|
|
|
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c |
|
index f17a82fcdf..ec4cf4eefa 100644 |
|
--- a/src/core/load-fragment.c |
|
+++ b/src/core/load-fragment.c |
|
@@ -604,7 +604,11 @@ int config_parse_exec(const char *unit, |
|
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 */ |
|
diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c |
|
index 9f3e3a227e..5500983322 100644 |
|
--- a/src/test/test-unit-file.c |
|
+++ b/src/test/test-unit-file.c |
|
@@ -318,6 +318,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); |
|
} |
|
|
|
|