1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:27:45 +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:
Ben Wiederhake 2021-10-30 00:45:23 +02:00 committed by Andreas Kling
parent 88ca12f037
commit c05c5a7ff4
28 changed files with 83 additions and 65 deletions

View file

@ -127,9 +127,10 @@ KResult MasterPTY::ioctl(OpenFileDescription& description, unsigned request, Use
return EINVAL;
}
String MasterPTY::absolute_path(const OpenFileDescription&) const
KResultOr<NonnullOwnPtr<KString>> MasterPTY::pseudo_path(const OpenFileDescription&) const
{
return String::formatted("ptm:{}", m_pts_name);
// FIXME: Replace this and others of this pattern by KString::formatted()
return KString::try_create(String::formatted("ptm:{}", m_pts_name));
}
}

View file

@ -26,7 +26,7 @@ public:
void notify_slave_closed(Badge<SlavePTY>);
bool is_closed() const { return m_closed; }
virtual String absolute_path(const OpenFileDescription&) const override;
virtual KResultOr<NonnullOwnPtr<KString>> pseudo_path(const OpenFileDescription&) const override;
private:
explicit MasterPTY(unsigned index, NonnullOwnPtr<DoubleBuffer> buffer);

View file

@ -576,6 +576,11 @@ KResult TTY::ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg)
return EINVAL;
}
KResultOr<NonnullOwnPtr<KString>> TTY::pseudo_path(const OpenFileDescription&) const
{
return KString::try_create(tty_name());
}
void TTY::set_size(unsigned short columns, unsigned short rows)
{
m_rows = rows;

View file

@ -26,7 +26,7 @@ public:
virtual bool can_read(const OpenFileDescription&, size_t) const override;
virtual bool can_write(const OpenFileDescription&, size_t) const override;
virtual KResult ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override final;
virtual String absolute_path(const OpenFileDescription&) const override { return tty_name(); }
virtual KResultOr<NonnullOwnPtr<KString>> pseudo_path(const OpenFileDescription&) const override;
virtual String const& tty_name() const = 0;