From: Mike Yuan Date: Mon, 5 May 2025 18:12:05 +0000 (+0200) Subject: path-util: introduce filename_or_absolute_path_is_valid() helper X-Git-Tag: v258-rc1~643^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=398b3e44722e5a3a7a78ce16aa6ece3dc80e72a6;p=thirdparty%2Fsystemd.git path-util: introduce filename_or_absolute_path_is_valid() helper --- diff --git a/src/basic/path-util.h b/src/basic/path-util.h index 647a884e398..671c1363c41 100644 --- a/src/basic/path-util.h +++ b/src/basic/path-util.h @@ -145,6 +145,12 @@ static inline bool path_is_safe(const char *p) { return path_is_valid_full(p, /* accept_dot_dot= */ false); } bool path_is_normalized(const char *p) _pure_; +static inline bool filename_or_absolute_path_is_valid(const char *p) { + if (path_is_absolute(p)) + return path_is_valid(p); + + return filename_is_valid(p); +} int file_in_same_dir(const char *path, const char *filename, char **ret); diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index 34511181bfe..560594d8a15 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -1512,7 +1512,7 @@ int bus_set_transient_exec_command( if (r < 0) return r; - if (!path_is_absolute(path) && !filename_is_valid(path)) + if (!filename_or_absolute_path_is_valid(path)) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "\"%s\" is neither a valid executable name nor an absolute path", path); diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index e718dbc76b9..ca95f334079 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -974,7 +974,7 @@ int config_parse_exec( return ignore ? 0 : -ENOEXEC; } - if (!(path_is_absolute(path) ? path_is_valid(path) : filename_is_valid(path))) { + if (!filename_or_absolute_path_is_valid(path)) { log_syntax(unit, ignore ? LOG_WARNING : LOG_ERR, filename, line, 0, "Neither a valid executable name nor an absolute path%s: %s", ignore ? ", ignoring" : "", path);