From: Lennart Poettering Date: Fri, 11 Feb 2022 13:05:01 +0000 (+0100) Subject: bootspec: port one more use of basename() to path_extract_filename() X-Git-Tag: v251-rc1~293^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=736783d42035e0e654508cf3ea0ae95e76dbc1f5;p=thirdparty%2Fsystemd.git bootspec: port one more use of basename() to path_extract_filename() --- diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 0076092c2ab..1f2bab3fb84 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();