From 7410616cd9dbbec97cf98d75324da5cda2b2f7a2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 30 Apr 2015 20:21:00 +0200 Subject: core: rework unit name validation and manipulation logic A variety of changes: - Make sure all our calls distuingish OOM from other errors if OOM is not the only error possible. - Be much stricter when parsing escaped paths, do not accept trailing or leading escaped slashes. - Change unit validation to take a bit mask for allowing plain names, instance names or template names or an combination thereof. - Refuse manipulating invalid unit name --- src/core/automount.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/core/automount.c') diff --git a/src/core/automount.c b/src/core/automount.c index 73b75f163e..1806fa39d3 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -167,8 +167,9 @@ static int automount_add_default_dependencies(Automount *a) { } static int automount_verify(Automount *a) { - bool b; _cleanup_free_ char *e = NULL; + int r; + assert(a); if (UNIT(a)->load_state != UNIT_LOADED) @@ -179,13 +180,11 @@ static int automount_verify(Automount *a) { return -EINVAL; } - e = unit_name_from_path(a->where, ".automount"); - if (!e) - return -ENOMEM; - - b = unit_has_name(UNIT(a), e); + r = unit_name_from_path(a->where, ".automount", &e); + if (r < 0) + return log_unit_error(UNIT(a)->id, "Failed to generate unit name from path: %m"); - if (!b) { + if (!unit_has_name(UNIT(a), e)) { log_unit_error(UNIT(a)->id, "%s's Where setting doesn't match unit name. Refusing.", UNIT(a)->id); return -EINVAL; } @@ -209,9 +208,9 @@ static int automount_load(Unit *u) { Unit *x; if (!a->where) { - a->where = unit_name_to_path(u->id); - if (!a->where) - return -ENOMEM; + r = unit_name_to_path(u->id, &a->where); + if (r < 0) + return r; } path_kill_slashes(a->where); -- cgit v1.2.3-54-g00ecf