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