path-util: introduce filename_or_absolute_path_is_valid() helper

This commit is contained in:
Mike Yuan
2025-05-05 20:12:05 +02:00
parent 91d5fad9fb
commit 398b3e4472
3 changed files with 8 additions and 2 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);