summaryrefslogtreecommitdiff
path: root/src/core/slice.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-05-05 13:39:14 -0700
committerLennart Poettering <lennart@poettering.net>2015-05-05 15:06:51 -0700
commit93c474725c0fb2530f093c106de0bce956544d29 (patch)
tree9302e649dfa6dce06f17fed666955e938a724dba /src/core/slice.c
parente05ad7bcc87f652cea321224f8eeb32e21d18e0c (diff)
core: be more strict when manipulating slices names and unescaping paths from unit names
Let's better be safe then sorry.
Diffstat (limited to 'src/core/slice.c')
-rw-r--r--src/core/slice.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/core/slice.c b/src/core/slice.c
index 0bebdbcbc6..b965850dab 100644
--- a/src/core/slice.c
+++ b/src/core/slice.c
@@ -93,27 +93,28 @@ static int slice_add_default_dependencies(Slice *s) {
return 0;
}
+
static int slice_verify(Slice *s) {
+ _cleanup_free_ char *parent = NULL;
+ int r;
+
assert(s);
if (UNIT(s)->load_state != UNIT_LOADED)
return 0;
- if (UNIT_DEREF(UNIT(s)->slice)) {
- char *a, *dash;
+ if (!slice_name_is_valid(UNIT(s)->id)) {
+ log_unit_error(UNIT(s)->id, "Slice name %s is not valid. Refusing.", UNIT(s)->id);
+ return -EINVAL;
+ }
- a = strdupa(UNIT(s)->id);
- dash = strrchr(a, '-');
- if (dash)
- strcpy(dash, ".slice");
- else
- a = (char*) SPECIAL_ROOT_SLICE;
+ r = slice_build_parent_slice(UNIT(s)->id, &parent);
+ if (r < 0)
+ return log_unit_error_errno(UNIT(s)->id, r, "Failed to determine parent slice: %m");
- if (!unit_has_name(UNIT_DEREF(UNIT(s)->slice), a)) {
- log_unit_error(UNIT(s)->id,
- "%s located outside its parent slice. Refusing.", UNIT(s)->id);
- return -EINVAL;
- }
+ if (parent ? !unit_has_name(UNIT_DEREF(UNIT(s)->slice), parent) : UNIT_ISSET(UNIT(s)->slice)) {
+ log_unit_error(UNIT(s)->id, "%s located outside its parent slice. Refusing.", UNIT(s)->id);
+ return -EINVAL;
}
return 0;