From: Yu Watanabe Date: Fri, 27 Jun 2025 01:07:21 +0000 (+0900) Subject: pretty-print: also chase symlinks in the last component X-Git-Tag: v258-rc1~227 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2f2977cab8ee94e5479d86c93c7a4346789a920a;p=thirdparty%2Fsystemd.git pretty-print: also chase symlinks in the last component Otherwise, this may shows files outside of the specified root directory. --- diff --git a/src/shared/pretty-print.c b/src/shared/pretty-print.c index 8be99a8d3f4..55bc585b833 100644 --- a/src/shared/pretty-print.c +++ b/src/shared/pretty-print.c @@ -6,6 +6,7 @@ #include #include "alloc-util.h" +#include "chase.h" #include "color-util.h" #include "conf-files.h" #include "constants.h" @@ -418,12 +419,16 @@ int conf_files_cat(const char *root, const char *name, CatFlags flags) { /* First locate the main config file, if any */ if (!is_collection) { STRV_FOREACH(prefix, prefixes) { - path = path_join(root, *prefix, name); - if (!path) + _cleanup_free_ char *p = path_join(*prefix, name); + if (!p) return log_oom(); - if (access(path, F_OK) == 0) - break; - path = mfree(path); + + r = chase_and_access(p, root, CHASE_PREFIX_ROOT, F_OK, &path); + if (r < 0) { + if (r != -ENOENT) + log_debug_errno(r, "Failed to chase %s%s, ignoring: %m", strempty(root), p); + continue; + } } if (!path) @@ -434,7 +439,7 @@ int conf_files_cat(const char *root, const char *name, CatFlags flags) { } /* Then locate the drop-ins, if any */ - r = conf_files_list_strv(&files, extension, root, 0, (const char* const*) dirs); + r = conf_files_list_strv(&files, extension, root, CONF_FILES_CHASE_BASENAME, (const char* const*) dirs); if (r < 0) return log_error_errno(r, "Failed to query file list: %m");