1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:38:10 +00:00

Kernel: Harden Socket::pseudo_path(..) implementations against OOM

Use the try variants of AK::StringBuilder append APIs to harden these
functions against OOM.
This commit is contained in:
Brian Gianforcaro 2022-01-09 00:59:12 -08:00 committed by Andreas Kling
parent ea66750640
commit ccbc3f8975
2 changed files with 13 additions and 13 deletions

View file

@ -358,21 +358,21 @@ StringView LocalSocket::socket_path() const
ErrorOr<NonnullOwnPtr<KString>> LocalSocket::pseudo_path(const OpenFileDescription& description) const
{
StringBuilder builder;
builder.append("socket:");
builder.append(socket_path());
TRY(builder.try_append("socket:"));
TRY(builder.try_append(socket_path()));
switch (role(description)) {
case Role::Listener:
builder.append(" (listening)");
TRY(builder.try_append(" (listening)"));
break;
case Role::Accepted:
builder.appendff(" (accepted from pid {})", origin_pid());
TRY(builder.try_appendff(" (accepted from pid {})", origin_pid()));
break;
case Role::Connected:
builder.appendff(" (connected to pid {})", acceptor_pid());
TRY(builder.try_appendff(" (connected to pid {})", acceptor_pid()));
break;
case Role::Connecting:
builder.append(" (connecting)");
TRY(builder.try_append(" (connecting)"));
break;
default:
break;