mirror of
https://github.com/morgan9e/systemd
synced 2026-04-15 17:06:39 +09:00
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:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user