diff options
author | Max Wipfli <mail@maxwipfli.ch> | 2021-07-06 12:58:03 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-07 15:32:17 +0200 |
commit | d5722eab36695a7be600f6c0b702721f2946e047 (patch) | |
tree | 1f4c47b777536188a00df74aec157c3954dccb6e /Kernel/Syscalls/unveil.cpp | |
parent | 0f8a6e574cdf638f81c73e782937a55d16225fe3 (diff) | |
download | serenity-d5722eab36695a7be600f6c0b702721f2946e047.zip |
Kernel: Custody::absolute_path() => try_create_absolute_path()
This converts most users of Custody::absolute_path() to use the new
try_create_absolute_path() API, and return ENOMEM if the KString
allocation fails.
Diffstat (limited to 'Kernel/Syscalls/unveil.cpp')
-rw-r--r-- | Kernel/Syscalls/unveil.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/Kernel/Syscalls/unveil.cpp b/Kernel/Syscalls/unveil.cpp index 39099be3a0..ef8fa20fa0 100644 --- a/Kernel/Syscalls/unveil.cpp +++ b/Kernel/Syscalls/unveil.cpp @@ -86,19 +86,25 @@ KResultOr<FlatPtr> Process::sys$unveil(Userspace<const Syscall::SC_unveil_params // because they most likely intend the program to create the file for them later on. // If this case is encountered, the parent node of the path is returned and the custody of that inode is used instead. RefPtr<Custody> parent_custody; // Parent inode in case of ENOENT - String new_unveiled_path; + OwnPtr<KString> new_unveiled_path; auto custody_or_error = VFS::the().resolve_path_without_veil(path.view(), root_directory(), &parent_custody); if (!custody_or_error.is_error()) { - new_unveiled_path = custody_or_error.value()->absolute_path(); + new_unveiled_path = custody_or_error.value()->try_create_absolute_path(); + if (!new_unveiled_path) + return ENOMEM; } else if (custody_or_error.error() == -ENOENT && parent_custody && (new_permissions & UnveilAccess::CreateOrRemove)) { - auto basename = KLexicalPath::basename(path.view()); - new_unveiled_path = String::formatted("{}/{}", parent_custody->absolute_path(), basename); + auto parent_custody_path = parent_custody->try_create_absolute_path(); + if (!parent_custody_path) + return ENOMEM; + new_unveiled_path = KLexicalPath::try_join(parent_custody_path->view(), KLexicalPath::basename(path.view())); + if (!new_unveiled_path) + return ENOMEM; } else { // FIXME Should this be EINVAL? return custody_or_error.error(); } - auto path_parts = KLexicalPath::parts(new_unveiled_path); + auto path_parts = KLexicalPath::parts(new_unveiled_path->view()); auto it = path_parts.begin(); auto& matching_node = m_unveiled_paths.traverse_until_last_accessible_node(it, path_parts.end()); if (it.is_end()) { @@ -123,7 +129,7 @@ KResultOr<FlatPtr> Process::sys$unveil(Userspace<const Syscall::SC_unveil_params matching_node.insert( it, path_parts.end(), - { new_unveiled_path, (UnveilAccess)new_permissions, true }, + { new_unveiled_path->view(), (UnveilAccess)new_permissions, true }, [](auto& parent, auto& it) -> Optional<UnveilMetadata> { auto path = String::formatted("{}/{}", parent.path(), *it); return UnveilMetadata { path, parent.permissions(), false }; |