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/cryptsetup/cryptsetup-generator.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/cryptsetup') diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index 5d234e6a5a..755ee5d88d 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -78,9 +78,9 @@ static int create_disk( if (!e) return log_oom(); - n = unit_name_build("systemd-cryptsetup", e, ".service"); - if (!n) - return log_oom(); + r = unit_name_build("systemd-cryptsetup", e, ".service", &n); + if (r < 0) + return log_error_errno(r, "Failed to generate unit name: %m"); p = strjoin(arg_dest, "/", n, NULL); if (!p) @@ -90,9 +90,9 @@ static int create_disk( if (!u) return log_oom(); - d = unit_name_from_path(u, ".device"); - if (!d) - return log_oom(); + r = unit_name_from_path(u, ".device", &d); + if (r < 0) + return log_error_errno(r, "Failed to generate unit name: %m"); f = fopen(p, "wxe"); if (!f) @@ -128,11 +128,11 @@ static int create_disk( if (!path_equal(uu, "/dev/null")) { if (is_device_path(uu)) { - _cleanup_free_ char *dd; + _cleanup_free_ char *dd = NULL; - dd = unit_name_from_path(uu, ".device"); - if (!dd) - return log_oom(); + r = unit_name_from_path(uu, ".device", &dd); + if (r < 0) + return log_error_errno(r, "Failed to generate unit name: %m"); fprintf(f, "After=%1$s\nRequires=%1$s\n", dd); } else -- cgit v1.2.3-54-g00ecf