Procházet zdrojové kódy

Kernel: Use purpose-sized buffers when resolving inodes as links

Tim Schumacher před 2 roky
rodič
revize
6f524e35a7
1 změnil soubory, kde provedl 8 přidání a 2 odebrání
  1. 8 2
      Kernel/FileSystem/Inode.cpp

+ 8 - 2
Kernel/FileSystem/Inode.cpp

@@ -80,8 +80,14 @@ ErrorOr<NonnullRefPtr<Custody>> Inode::resolve_as_link(Credentials const& creden
     // The default implementation simply treats the stored
     // The default implementation simply treats the stored
     // contents as a path and resolves that. That is, it
     // contents as a path and resolves that. That is, it
     // behaves exactly how you would expect a symlink to work.
     // behaves exactly how you would expect a symlink to work.
-    auto contents = TRY(read_entire());
-    return VirtualFileSystem::the().resolve_path(credentials, StringView { contents->bytes() }, base, out_parent, options, symlink_recursion_level);
+
+    // Make sure that our assumptions about the path length hold up.
+    // Note that this doesn't mean that the reported size can be trusted, some inodes just report zero.
+    VERIFY(size() <= MAXPATHLEN);
+
+    Array<u8, MAXPATHLEN> contents;
+    auto read_bytes = TRY(read_until_filled_or_end(0, contents.size(), UserOrKernelBuffer::for_kernel_buffer(contents.data()), nullptr));
+    return VirtualFileSystem::the().resolve_path(credentials, StringView { contents.span().trim(read_bytes) }, base, out_parent, options, symlink_recursion_level);
 }
 }
 
 
 Inode::Inode(FileSystem& fs, InodeIndex index)
 Inode::Inode(FileSystem& fs, InodeIndex index)