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

@@ -1037,14 +1037,14 @@ bool filename_is_valid(const char *p) {
return true;
}
bool path_is_valid(const char *p) {
bool path_is_valid_full(const char *p, bool accept_dot_dot) {
if (isempty(p))
return false;
for (const char *e = p;;) {
int r;
r = path_find_first_component(&e, /* accept_dot_dot= */ true, NULL);
r = path_find_first_component(&e, accept_dot_dot, NULL);
if (r < 0)
return false;