[systemd-commits] 2 commits - src/core src/test
Daniel Mack
zonque at kemper.freedesktop.org
Mon Jun 1 09:10:24 PDT 2015
src/core/load-fragment.c | 2 +-
src/test/test-unit-file.c | 19 +++++++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
New commits:
commit 80979f1ce4dadf797a42e85a97dc10960c1f6509
Author: Daniel Mack <daniel at zonque.org>
Date: Mon Jun 1 18:05:02 2015 +0200
test-unit-file: add test for improperly escaped exec string
Add a regression test for the recent breakage of handling improperly
escaped exec strings in unit files.
Code contributed by Martin Pitt:
https://bugs.freedesktop.org/show_bug.cgi?id=90794
diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c
index a9711ac..31b12d5 100644
--- a/src/test/test-unit-file.c
+++ b/src/test/test-unit-file.c
@@ -225,6 +225,15 @@ static void test_config_parse_exec(void) {
check_execcommand(c1,
"/sbin/find", NULL, ";", "x", false);
+ log_info("/* encoded semicolon */");
+ r = config_parse_exec(NULL, "fake", 5, "section", 1,
+ "LValue", 0,
+ "/bin/find \\073",
+ &c, NULL);
+ assert_se(r >= 0);
+ c1 = c1->command_next;
+ check_execcommand(c1, "/bin/find", NULL, "\\073", NULL, false);
+
log_info("/* spaces in the filename */");
r = config_parse_exec(NULL, "fake", 5, "section", 1,
"LValue", 0,
@@ -296,6 +305,16 @@ static void test_config_parse_exec(void) {
c1 = c1->command_next;
check_execcommand(c1, "/path ", NULL, NULL, NULL, false);
+ log_info("/* quoted backslashes */");
+ r = config_parse_exec(NULL, "fake", 5, "section", 1,
+ "LValue", 0,
+ "/bin/grep '\\w+\\K'",
+ &c, NULL);
+ assert_se(r >= 0);
+ c1 = c1->command_next;
+ check_execcommand(c1, "/bin/grep", NULL, "\\w+\\K", NULL, false);
+
+
log_info("/* trailing backslash: \\ */");
/* backslash is invalid */
r = config_parse_exec(NULL, "fake", 4, "section", 1,
commit 22874a348fb1540c1a2b7907748fc57c9756a7ed
Author: Daniel Mack <daniel at zonque.org>
Date: Mon Jun 1 17:49:04 2015 +0200
load-fragment: use UNESCAPE_RELAX flag to parse exec directives
The cunescape() helper function used to handle unknown escaping sequences
gracefully by copying them over verbatim.
Commit 527b7a42 ("util: rework cunescape(), improve error handling") added
a flag to make that behavior optional, and changed to default to error out
with -EINVAL otherwise.
However, config_parse_exec(), which is used to parse the
Exec{Start,Stop}{Post,Pre,} directives of unit files, was not changed along
with that commit, which means that directives with improperly escaped
command line strings are no longer parsed.
Relevant bugreports include:
https://bugs.freedesktop.org/show_bug.cgi?id=90794
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=787256
Fix this by passing UNESCAPE_RELAX to config_parse_exec() in order to
restore the original behavior.
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index c95c110..df5fe6f 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -610,7 +610,7 @@ int config_parse_exec(
else
skip = strneq(word, "\\;", MAX(l, 1U));
- r = cunescape_length(word + skip, l - skip, 0, &c);
+ r = cunescape_length(word + skip, l - skip, UNESCAPE_RELAX, &c);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to unescape command line, ignoring: %s", rvalue);
r = 0;
More information about the systemd-commits
mailing list