]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: fix StateDirectory= (and friends) safety checks when decoding transient unit...
authorLennart Poettering <lennart@poettering.net>
Mon, 2 Oct 2017 08:50:07 +0000 (10:50 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 2 Oct 2017 15:41:44 +0000 (17:41 +0200)
Let's make sure relative directories such as "foo/bar" are accepted, by
using the same validation checks as in unit file parsing.

src/core/dbus-execute.c
src/core/load-fragment.c
src/shared/bus-unit-util.c

index 40f6d9a3ffad2268be64a33f803055713d6148be..1a388f559218623ac64fa323254b6308293ab7b0 100644 (file)
@@ -2213,8 +2213,8 @@ int bus_exec_context_set_transient_property(
                         return r;
 
                 STRV_FOREACH(p, l) {
-                        if (!filename_is_valid(*p))
-                                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s is not valid %s", name, *p);
+                        if (!path_is_safe(*p) || path_is_absolute(*p))
+                                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "%s= path is not valid: %s", name, *p);
                 }
 
                 if (mode != UNIT_CHECK) {
@@ -2235,7 +2235,6 @@ int bus_exec_context_set_transient_property(
                                 unit_write_drop_in_private_format(u, mode, name, "%s=", name);
                         } else {
                                 r = strv_extend_strv(dirs, l, true);
-
                                 if (r < 0)
                                         return -ENOMEM;
 
index d319934ee248d00839825d0635cab029303601e7..2c3783a9f0d1a6fa82894c8e0e180f9ba76ebc48 100644 (file)
@@ -3718,8 +3718,6 @@ int config_parse_exec_directories(
                 _cleanup_free_ char *word = NULL, *k = NULL;
 
                 r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES);
-                if (r == 0)
-                        return 0;
                 if (r == -ENOMEM)
                         return log_oom();
                 if (r < 0) {
@@ -3727,6 +3725,8 @@ int config_parse_exec_directories(
                                    "Invalid syntax, ignoring: %s", rvalue);
                         return 0;
                 }
+                if (r == 0)
+                        return 0;
 
                 r = unit_full_printf(u, word, &k);
                 if (r < 0) {
@@ -3737,7 +3737,7 @@ int config_parse_exec_directories(
 
                 if (!path_is_safe(k) || path_is_absolute(k)) {
                         log_syntax(unit, LOG_ERR, filename, line, 0,
-                                   "%s is not valid, ignoring assignment: %s", lvalue, rvalue);
+                                   "%s= path is not valid, ignoring assignment: %s", lvalue, rvalue);
                         continue;
                 }
 
index d216df465f45e8222a665be21d472f05d2f8a1dd..a08f17d8210d3b7734589e54bb29b36ba52428b9 100644 (file)
@@ -959,9 +959,10 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
                         _cleanup_free_ char *word = NULL;
 
                         r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES);
+                        if (r == -ENOMEM)
+                                return log_oom();
                         if (r < 0)
                                 return log_error_errno(r, "Failed to parse %s value %s", field, eq);
-
                         if (r == 0)
                                 break;