diff options
author | Max Wipfli <mail@maxwipfli.ch> | 2021-07-06 12:05:50 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-07 15:32:17 +0200 |
commit | 1f792faf34f74f7c01181470dd91453ff1d3b760 (patch) | |
tree | 5206cc072ba60ab84d9889e584cd635b5960f283 /Kernel/FileSystem/VirtualFileSystem.cpp | |
parent | ee342f5ec3cf6891fba8f1fffa819b0d17d2b02b (diff) | |
download | serenity-1f792faf34f74f7c01181470dd91453ff1d3b760.zip |
Kernel: Add KLexicalPath::try_join and use it
This adds KLexicalPath::try_join(). As this cannot be done without
allocation, it uses KString and can fail. This patch also uses it at one
place. All the other cases of String::formatted("{}/{}", ...) currently
rely on the return value being a String, which means they cannot easily
be converted to use the new API.
Diffstat (limited to 'Kernel/FileSystem/VirtualFileSystem.cpp')
-rw-r--r-- | Kernel/FileSystem/VirtualFileSystem.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index c67a38a6dc..be3993fcb1 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -361,7 +361,10 @@ KResult VFS::mknod(StringView path, mode_t mode, dev_t dev, Custody& base) KResultOr<NonnullRefPtr<FileDescription>> VFS::create(StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> owner) { auto basename = KLexicalPath::basename(path); - if (auto result = validate_path_against_process_veil(String::formatted("{}/{}", parent_custody.absolute_path(), basename), options); result.is_error()) + auto full_path = KLexicalPath::try_join(parent_custody.absolute_path(), basename); + if (!full_path) + return ENOMEM; + if (auto result = validate_path_against_process_veil(full_path->view(), options); result.is_error()) return result; if (!is_socket(mode) && !is_fifo(mode) && !is_block_device(mode) && !is_character_device(mode)) { |