mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 17:35:08 +00:00
Kernel: Fix resolving symlinks in the middle of a path.
If a symlink is not the last part of a path, the remaining part of the path has to be further resolved against the symlink target. With this, a path containing a symlink always resolves to the target of the first (leftmost) symlink in it, for example any path of form /proc/self/... resolves to the corresponding /proc/pid directory.
This commit is contained in:
parent
75df45d709
commit
629501049f
1 changed files with 17 additions and 1 deletions
|
@ -697,12 +697,28 @@ KResultOr<Retained<Custody>> VFS::resolve_path(StringView path, Custody& base, R
|
||||||
return KResult(-ENOENT);
|
return KResult(-ENOENT);
|
||||||
|
|
||||||
// FIXME: We should limit the recursion here and return -ELOOP if it goes to deep.
|
// FIXME: We should limit the recursion here and return -ELOOP if it goes to deep.
|
||||||
return resolve_path(
|
auto symlink_target = resolve_path(
|
||||||
StringView(symlink_contents.pointer(),
|
StringView(symlink_contents.pointer(),
|
||||||
symlink_contents.size()),
|
symlink_contents.size()),
|
||||||
*current_parent,
|
*current_parent,
|
||||||
parent_custody,
|
parent_custody,
|
||||||
options);
|
options);
|
||||||
|
|
||||||
|
if (symlink_target.is_error())
|
||||||
|
return symlink_target;
|
||||||
|
|
||||||
|
bool have_more_parts = i + 1 < parts.size();
|
||||||
|
if (i + 1 == parts.size() - 1 && parts[i + 1].is_empty())
|
||||||
|
have_more_parts = false;
|
||||||
|
|
||||||
|
if (!have_more_parts)
|
||||||
|
return symlink_target;
|
||||||
|
|
||||||
|
const char* remaining_path_chars = parts[i + 1].characters();
|
||||||
|
int remaining_path_length = path.length() - (remaining_path_chars - path.characters());
|
||||||
|
StringView remaining_path { remaining_path_chars, remaining_path_length };
|
||||||
|
|
||||||
|
return resolve_path(remaining_path, *symlink_target.value(), parent_custody, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return custody_chain.last();
|
return custody_chain.last();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue