mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 22:18:11 +00:00
Kernel: Clarify ambiguous {File,Description}::absolute_path
Found due to smelly code in InodeFile::absolute_path. In particular, this replaces the following misleading methods: File::absolute_path This method *never* returns an actual path, and if called on an InodeFile (which is impossible), it would VERIFY_NOT_REACHED(). OpenFileDescription::try_serialize_absolute_path OpenFileDescription::absolute_path These methods do not guarantee to return an actual path (just like the other method), and just like Custody::absolute_path they do not guarantee accuracy. In particular, just renaming the method made a TOCTOU bug obvious. The new method signatures use KResultOr, just like try_serialize_absolute_path() already did.
This commit is contained in:
parent
88ca12f037
commit
c05c5a7ff4
28 changed files with 83 additions and 65 deletions
|
@ -80,9 +80,10 @@ KResultOr<NonnullRefPtr<Inode>> Process::lookup_stacks_directory(const ProcFS& p
|
|||
KResultOr<size_t> Process::procfs_get_file_description_link(unsigned fd, KBufferBuilder& builder) const
|
||||
{
|
||||
auto file_description = TRY(m_fds.open_file_description(fd));
|
||||
auto data = file_description->absolute_path();
|
||||
TRY(builder.append(data));
|
||||
return data.length();
|
||||
// Note: These links are not guaranteed to point to actual VFS paths, just like in other kernels.
|
||||
auto data = TRY(file_description->pseudo_path());
|
||||
TRY(builder.append(data->view()));
|
||||
return data->length();
|
||||
}
|
||||
|
||||
KResult Process::traverse_file_descriptions_directory(unsigned fsid, Function<bool(FileSystem::DirectoryEntryView const&)> callback) const
|
||||
|
@ -187,7 +188,9 @@ KResult Process::procfs_get_fds_stats(KBufferBuilder& builder) const
|
|||
RefPtr<OpenFileDescription> description = file_description_metadata.description();
|
||||
auto description_object = array.add_object();
|
||||
description_object.add("fd", count);
|
||||
description_object.add("absolute_path", description->absolute_path());
|
||||
// TODO: Better OOM handling.
|
||||
auto pseudo_path_or_error = description->pseudo_path();
|
||||
description_object.add("absolute_path", pseudo_path_or_error.is_error() ? "???"sv : pseudo_path_or_error.value()->view());
|
||||
description_object.add("seekable", description->file().is_seekable());
|
||||
description_object.add("class", description->file().class_name());
|
||||
description_object.add("offset", description->offset());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue