mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:57:44 +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
|
@ -456,10 +456,10 @@ bool IPv4Socket::did_receive(const IPv4Address& source_address, u16 source_port,
|
|||
return true;
|
||||
}
|
||||
|
||||
String IPv4Socket::absolute_path(const OpenFileDescription&) const
|
||||
KResultOr<NonnullOwnPtr<KString>> IPv4Socket::pseudo_path(const OpenFileDescription&) const
|
||||
{
|
||||
if (m_role == Role::None)
|
||||
return "socket";
|
||||
return KString::try_create("socket"sv);
|
||||
|
||||
StringBuilder builder;
|
||||
builder.append("socket:");
|
||||
|
@ -485,7 +485,7 @@ String IPv4Socket::absolute_path(const OpenFileDescription&) const
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
return builder.to_string();
|
||||
return KString::try_create(builder.to_string());
|
||||
}
|
||||
|
||||
KResult IPv4Socket::setsockopt(int level, int option, Userspace<const void*> user_value, socklen_t user_value_size)
|
||||
|
|
|
@ -61,7 +61,7 @@ public:
|
|||
|
||||
IPv4SocketTuple tuple() const { return IPv4SocketTuple(m_local_address, m_local_port, m_peer_address, m_peer_port); }
|
||||
|
||||
String absolute_path(const OpenFileDescription& description) const override;
|
||||
KResultOr<NonnullOwnPtr<KString>> pseudo_path(const OpenFileDescription& description) const override;
|
||||
|
||||
u8 type_of_service() const { return m_type_of_service; }
|
||||
u8 ttl() const { return m_ttl; }
|
||||
|
|
|
@ -355,7 +355,7 @@ StringView LocalSocket::socket_path() const
|
|||
return m_path->view();
|
||||
}
|
||||
|
||||
String LocalSocket::absolute_path(const OpenFileDescription& description) const
|
||||
KResultOr<NonnullOwnPtr<KString>> LocalSocket::pseudo_path(const OpenFileDescription& description) const
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append("socket:");
|
||||
|
@ -378,7 +378,7 @@ String LocalSocket::absolute_path(const OpenFileDescription& description) const
|
|||
break;
|
||||
}
|
||||
|
||||
return builder.to_string();
|
||||
return KString::try_create(builder.to_string());
|
||||
}
|
||||
|
||||
KResult LocalSocket::getsockopt(OpenFileDescription& description, int level, int option, Userspace<void*> value, Userspace<socklen_t*> value_size)
|
||||
|
|
|
@ -32,7 +32,7 @@ public:
|
|||
static void for_each(Function<void(const LocalSocket&)>);
|
||||
|
||||
StringView socket_path() const;
|
||||
String absolute_path(const OpenFileDescription& description) const override;
|
||||
KResultOr<NonnullOwnPtr<KString>> pseudo_path(const OpenFileDescription& description) const override;
|
||||
|
||||
// ^Socket
|
||||
virtual KResult bind(Userspace<const sockaddr*>, socklen_t) override;
|
||||
|
|
|
@ -105,7 +105,7 @@ public:
|
|||
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override final;
|
||||
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override final;
|
||||
virtual KResult stat(::stat&) const override;
|
||||
virtual String absolute_path(const OpenFileDescription&) const override = 0;
|
||||
virtual KResultOr<NonnullOwnPtr<KString>> pseudo_path(const OpenFileDescription&) const override = 0;
|
||||
|
||||
bool has_receive_timeout() const { return m_receive_timeout != Time::zero(); }
|
||||
const Time& receive_timeout() const { return m_receive_timeout; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue