From 736783d42035e0e654508cf3ea0ae95e76dbc1f5 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 11 Feb 2022 14:05:01 +0100 Subject: [PATCH] bootspec: port one more use of basename() to path_extract_filename() --- src/shared/bootspec.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 0076092c2a..1f2bab3fb8 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -64,26 +64,28 @@ static int boot_entry_load( _cleanup_fclose_ FILE *f = NULL; unsigned line = 1; - char *b, *c; + char *c; int r; assert(root); assert(path); assert(entry); - c = endswith_no_case(path, ".conf"); - if (!c) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid loader entry file suffix: %s", path); + r = path_extract_filename(path, &tmp.id); + if (r < 0) + return log_error_errno(r, "Failed to extract file name from path '%s': %m", path); - b = basename(path); - tmp.id = strdup(b); - tmp.id_old = strndup(b, c - b); - if (!tmp.id || !tmp.id_old) - return log_oom(); + c = endswith_no_case(tmp.id, ".conf"); + if (!c) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid loader entry file suffix: %s", tmp.id); if (!efi_loader_entry_name_valid(tmp.id)) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invalid loader entry name: %s", tmp.id); + tmp.id_old = strndup(tmp.id, c - tmp.id); + if (!tmp.id_old) + return log_oom(); + tmp.path = strdup(path); if (!tmp.path) return log_oom();