From ddc950ce42f2db5d75097623859d47e02f0ed99c Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Wed, 28 Jul 2021 01:49:04 -0700 Subject: [PATCH] Kernel: Avoid file descriptor leak in Process::sys$socketpair on error Previously it was possible to leak the file descriptor if we error out after allocating the first descriptor. Now we perform both fd allocations back to back so we can handle the potential error when processing the second fd allocation. --- Kernel/Net/LocalSocket.h | 2 +- Kernel/Syscalls/socket.cpp | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Kernel/Net/LocalSocket.h b/Kernel/Net/LocalSocket.h index 818608d8a5d..1fc56c59a71 100644 --- a/Kernel/Net/LocalSocket.h +++ b/Kernel/Net/LocalSocket.h @@ -15,8 +15,8 @@ namespace Kernel { class FileDescription; struct SocketPair { + NonnullRefPtr description0; NonnullRefPtr description1; - NonnullRefPtr description2; }; class LocalSocket final : public Socket { diff --git a/Kernel/Syscalls/socket.cpp b/Kernel/Syscalls/socket.cpp index 522881c2249..e8d3a3bbda1 100644 --- a/Kernel/Syscalls/socket.cpp +++ b/Kernel/Syscalls/socket.cpp @@ -412,21 +412,23 @@ KResultOr Process::sys$socketpair(Userspace