fs-util: rename path_is_safe() → path_is_normalized()

Already, path_is_safe() refused paths container the "." dir. Doing that
isn't strictly necessary to be "safe" by most definitions of the word.
But it is necessary in order to consider a path "normalized". Hence,
"path_is_safe()" is slightly misleading a name, but
"path_is_normalize()" is more descriptive, hence let's rename things
accordingly.

No functional changes.
This commit is contained in:
Lennart Poettering
2017-11-17 11:13:44 +01:00
parent 5db9818772
commit 99be45a46f
11 changed files with 23 additions and 24 deletions
+2 -2
View File
@@ -1278,7 +1278,7 @@ int cg_split_spec(const char *spec, char **controller, char **path) {
assert(spec);
if (*spec == '/') {
if (!path_is_safe(spec))
if (!path_is_normalized(spec))
return -EINVAL;
if (path) {
@@ -1331,7 +1331,7 @@ int cg_split_spec(const char *spec, char **controller, char **path) {
return -ENOMEM;
}
if (!path_is_safe(u) ||
if (!path_is_normalized(u) ||
!path_is_absolute(u)) {
free(t);
free(u);
+2 -2
View File
@@ -509,7 +509,7 @@ static int getenv_tmp_dir(const char **ret_path) {
r = -ENOTDIR;
goto next;
}
if (!path_is_safe(e)) {
if (!path_is_normalized(e)) {
r = -EPERM;
goto next;
}
@@ -707,7 +707,7 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
if (errno == ENOENT &&
(flags & CHASE_NONEXISTENT) &&
(isempty(todo) || path_is_safe(todo))) {
(isempty(todo) || path_is_normalized(todo))) {
/* If CHASE_NONEXISTENT is set, and the path does not exist, then that's OK, return
* what we got so far. But don't allow this if the remaining path contains "../ or "./"
+1 -2
View File
@@ -721,7 +721,7 @@ bool filename_is_valid(const char *p) {
return true;
}
bool path_is_safe(const char *p) {
bool path_is_normalized(const char *p) {
if (isempty(p))
return false;
@@ -735,7 +735,6 @@ bool path_is_safe(const char *p) {
if (strlen(p)+1 > PATH_MAX)
return false;
/* The following two checks are not really dangerous, but hey, they still are confusing */
if (startswith(p, "./") || endswith(p, "/.") || strstr(p, "/./"))
return false;
+1 -1
View File
@@ -131,7 +131,7 @@ int parse_path_argument_and_warn(const char *path, bool suppress_root, char **ar
char* dirname_malloc(const char *path);
bool filename_is_valid(const char *p) _pure_;
bool path_is_safe(const char *p) _pure_;
bool path_is_normalized(const char *p) _pure_;
char *file_in_same_dir(const char *path, const char *filename);
+2 -2
View File
@@ -382,7 +382,7 @@ int unit_name_path_escape(const char *f, char **ret) {
if (STR_IN_SET(p, "/", ""))
s = strdup("-");
else {
if (!path_is_safe(p))
if (!path_is_normalized(p))
return -EINVAL;
/* Truncate trailing slashes */
@@ -432,7 +432,7 @@ int unit_name_path_unescape(const char *f, char **ret) {
if (!s)
return -ENOMEM;
if (!path_is_safe(s)) {
if (!path_is_normalized(s)) {
free(s);
return -EINVAL;
}
+1 -1
View File
@@ -605,7 +605,7 @@ bool valid_home(const char *p) {
if (!path_is_absolute(p))
return false;
if (!path_is_safe(p))
if (!path_is_normalized(p))
return false;
/* Colons are used as field separators, and hence not OK */