mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-03 08:00:58 +00:00
parent
7651c94bf5
commit
fb2e0b50c8
@ -130,6 +130,12 @@ class Genode::Path_base
|
|||||||
|
|
||||||
static void strip_double_dot_dirs(char *path)
|
static void strip_double_dot_dirs(char *path)
|
||||||
{
|
{
|
||||||
|
bool path_was_absolute = absolute(path);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Strip any occurrence of "/.." and the previous path
|
||||||
|
* element (including leading slash) if one exists.
|
||||||
|
*/
|
||||||
unsigned i;
|
unsigned i;
|
||||||
while ((i = find_double_dot_dir(path))) {
|
while ((i = find_double_dot_dir(path))) {
|
||||||
|
|
||||||
@ -141,12 +147,27 @@ class Genode::Path_base
|
|||||||
while (cut_start > 0 && path[cut_start - 1] != '/')
|
while (cut_start > 0 && path[cut_start - 1] != '/')
|
||||||
cut_start--;
|
cut_start--;
|
||||||
|
|
||||||
/* skip slash in front of the pair of dots */
|
/* skip slash in front of the previous path element */
|
||||||
if (cut_start > 0)
|
if (cut_start > 0)
|
||||||
cut_start--;
|
cut_start--;
|
||||||
|
|
||||||
strip(path + cut_start, cut_end - cut_start);
|
strip(path + cut_start, cut_end - cut_start);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (path_was_absolute) {
|
||||||
|
/* restore the leading slash if it got stripped */
|
||||||
|
if (empty(path))
|
||||||
|
copy_cstring(path, "/", 2);
|
||||||
|
} else {
|
||||||
|
/* remove leading ".." if present */
|
||||||
|
if (path[0] == '.' && path[1] == '.'
|
||||||
|
&& (path[2] == 0 || path[2] == '/'))
|
||||||
|
strip(path, 2);
|
||||||
|
|
||||||
|
/* remove leading slash if one is present now */
|
||||||
|
if (path[0] == '/')
|
||||||
|
strip(path, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user