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/mount.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'src/core/mount.c') diff --git a/src/core/mount.c b/src/core/mount.c index d0c41a73a9..65a66b468f 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -435,7 +435,7 @@ static int mount_add_default_dependencies(Mount *m) { static int mount_verify(Mount *m) { _cleanup_free_ char *e = NULL; - bool b; + int r; assert(m); @@ -445,12 +445,11 @@ static int mount_verify(Mount *m) { if (!m->from_fragment && !m->from_proc_self_mountinfo) return -ENOENT; - e = unit_name_from_path(m->where, ".mount"); - if (!e) - return -ENOMEM; + r = unit_name_from_path(m->where, ".mount", &e); + if (r < 0) + return log_unit_error_errno(UNIT(m)->id, r, "Failed to generate unit name from mount path: %m"); - b = unit_has_name(UNIT(m), e); - if (!b) { + if (!unit_has_name(UNIT(m), e)) { log_unit_error(UNIT(m)->id, "%s's Where= setting doesn't match unit name. Refusing.", UNIT(m)->id); return -EINVAL; } @@ -483,9 +482,9 @@ static int mount_add_extras(Mount *m) { m->from_fragment = true; if (!m->where) { - m->where = unit_name_to_path(u->id); - if (!m->where) - return -ENOMEM; + r = unit_name_to_path(u->id, &m->where); + if (r < 0) + return r; } path_kill_slashes(m->where); @@ -1419,9 +1418,9 @@ static int mount_setup_unit( if (!is_path(where)) return 0; - e = unit_name_from_path(where, ".mount"); - if (!e) - return -ENOMEM; + r = unit_name_from_path(where, ".mount", &e); + if (r < 0) + return r; u = manager_get_unit(m, e); if (!u) { -- cgit v1.2.3-54-g00ecf