path-util: introduce path_is_safe()

The function is similar to path_is_valid(), but it refuses paths which
contain ".." component.
This commit is contained in:
Yu Watanabe
2021-05-01 02:37:31 +09:00
parent 6636883564
commit 32df2e1447
3 changed files with 40 additions and 22 deletions

View File

@@ -155,7 +155,13 @@ int path_extract_filename(const char *p, char **ret);
int path_extract_directory(const char *p, char **ret);
bool filename_is_valid(const char *p) _pure_;
bool path_is_valid(const char *p) _pure_;
bool path_is_valid_full(const char *p, bool accept_dot_dot) _pure_;
static inline bool path_is_valid(const char *p) {
return path_is_valid_full(p, true);
}
static inline bool path_is_safe(const char *p) {
return path_is_valid_full(p, false);
}
bool path_is_normalized(const char *p) _pure_;
char *file_in_same_dir(const char *path, const char *filename);