mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:18:11 +00:00
Kernel: Implement recursion limit on path resolution
Cautiously use 5 as a limit for now so that we don't blow the stack. This can be increased in the future if we are sure that we won't be blowing the stack, or if the implementation is changed to not use recursion :^)
This commit is contained in:
parent
3623e35978
commit
0e45b9423b
2 changed files with 8 additions and 11 deletions
|
@ -11,6 +11,7 @@
|
||||||
//#define VFS_DEBUG
|
//#define VFS_DEBUG
|
||||||
|
|
||||||
static VFS* s_the;
|
static VFS* s_the;
|
||||||
|
static constexpr int symlink_recursion_limit { 5 }; // FIXME: increase?
|
||||||
|
|
||||||
VFS& VFS::the()
|
VFS& VFS::the()
|
||||||
{
|
{
|
||||||
|
@ -615,7 +616,6 @@ InodeIdentifier VFS::Mount::host() const
|
||||||
return m_host_custody->inode().identifier();
|
return m_host_custody->inode().identifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void VFS::for_each_mount(Function<void(const Mount&)> callback) const
|
void VFS::for_each_mount(Function<void(const Mount&)> callback) const
|
||||||
{
|
{
|
||||||
for (auto& mount : m_mounts) {
|
for (auto& mount : m_mounts) {
|
||||||
|
@ -635,10 +635,12 @@ Custody& VFS::root_custody()
|
||||||
return *m_root_custody;
|
return *m_root_custody;
|
||||||
}
|
}
|
||||||
|
|
||||||
KResultOr<NonnullRefPtr<Custody>> VFS::resolve_path(StringView path, Custody& base, RefPtr<Custody>* parent_custody, int options)
|
KResultOr<NonnullRefPtr<Custody>> VFS::resolve_path(StringView path, Custody& base, RefPtr<Custody>* parent_custody, int options, int symlink_recursion_level)
|
||||||
{
|
{
|
||||||
// FIXME: resolve_path currently doesn't deal with .. and . . If path is ../. and base is /home/anon, it returns
|
// FIXME: resolve_path currently doesn't deal with .. and . . If path is ../. and base is /home/anon, it returns
|
||||||
// /home/anon/../. instead of /home .
|
// /home/anon/../. instead of /home .
|
||||||
|
if (symlink_recursion_level >= symlink_recursion_limit)
|
||||||
|
return KResult(-ELOOP);
|
||||||
|
|
||||||
if (path.is_empty())
|
if (path.is_empty())
|
||||||
return KResult(-EINVAL);
|
return KResult(-EINVAL);
|
||||||
|
@ -712,13 +714,8 @@ KResultOr<NonnullRefPtr<Custody>> VFS::resolve_path(StringView path, Custody& ba
|
||||||
if (!symlink_contents)
|
if (!symlink_contents)
|
||||||
return KResult(-ENOENT);
|
return KResult(-ENOENT);
|
||||||
|
|
||||||
// FIXME: We should limit the recursion here and return -ELOOP if it goes to deep.
|
auto symlink_path = StringView(symlink_contents.data(), symlink_contents.size());
|
||||||
auto symlink_target = resolve_path(
|
auto symlink_target = resolve_path(symlink_path, current_parent, parent_custody, options, symlink_recursion_level + 1);
|
||||||
StringView(symlink_contents.data(),
|
|
||||||
symlink_contents.size()),
|
|
||||||
current_parent,
|
|
||||||
parent_custody,
|
|
||||||
options);
|
|
||||||
|
|
||||||
if (symlink_target.is_error())
|
if (symlink_target.is_error())
|
||||||
return symlink_target;
|
return symlink_target;
|
||||||
|
@ -731,7 +728,7 @@ KResultOr<NonnullRefPtr<Custody>> VFS::resolve_path(StringView path, Custody& ba
|
||||||
return symlink_target;
|
return symlink_target;
|
||||||
|
|
||||||
StringView remaining_path = path.substring_view_starting_from_substring(parts[i + 1]);
|
StringView remaining_path = path.substring_view_starting_from_substring(parts[i + 1]);
|
||||||
return resolve_path(remaining_path, *symlink_target.value(), parent_custody, options);
|
return resolve_path(remaining_path, *symlink_target.value(), parent_custody, options, symlink_recursion_level + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return custody_chain.last();
|
return custody_chain.last();
|
||||||
|
|
|
@ -88,7 +88,7 @@ public:
|
||||||
void sync();
|
void sync();
|
||||||
|
|
||||||
Custody& root_custody();
|
Custody& root_custody();
|
||||||
KResultOr<NonnullRefPtr<Custody>> resolve_path(StringView path, Custody& base, RefPtr<Custody>* parent = nullptr, int options = 0);
|
KResultOr<NonnullRefPtr<Custody>> resolve_path(StringView path, Custody& base, RefPtr<Custody>* parent = nullptr, int options = 0, int symlink_recursion_level = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class FileDescription;
|
friend class FileDescription;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue