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/fstab-generator/fstab-generator.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/fstab-generator/fstab-generator.c') diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index 664ee2aa6f..167ec60dc5 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -83,9 +83,9 @@ static int add_swap( opts = filtered; } - name = unit_name_from_path(what, ".swap"); - if (!name) - return log_oom(); + r = unit_name_from_path(what, ".swap", &name); + if (r < 0) + return log_error_errno(r, "Failed to generate unit name: %m"); unit = strjoin(arg_dest, "/", name, NULL); if (!unit) @@ -224,9 +224,9 @@ static int add_mount( noauto = nofail = automount = false; } - name = unit_name_from_path(where, ".mount"); - if (!name) - return log_oom(); + r = unit_name_from_path(where, ".mount", &name); + if (r < 0) + return log_error_errno(r, "Failed to generate unit name: %m"); unit = strjoin(arg_dest, "/", name, NULL); if (!unit) @@ -290,9 +290,9 @@ static int add_mount( } if (automount) { - automount_name = unit_name_from_path(where, ".automount"); - if (!automount_name) - return log_oom(); + r = unit_name_from_path(where, ".automount", &automount_name); + if (r < 0) + return log_error_errno(r, "Failed to generate unit name: %m"); automount_unit = strjoin(arg_dest, "/", automount_name, NULL); if (!automount_unit) -- cgit v1.2.3-54-g00ecf