From 472a621589ebaccd8c5da93abce32a7f0105eaf6 Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Sun, 28 Aug 2022 16:24:19 +0200 Subject: [PATCH] Bsd: Fix ArgumentOutOfRangeException in SetSocketOption (#3633) * Bsd: Fix ArgumentOutOfRangeException in SetSocketOption * Ensure option level is Socket before checking for SoLinger --- .../HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs b/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs index b9adb5cc77..d2a8345887 100644 --- a/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs +++ b/Ryujinx.HLE/HOS/Services/Sockets/Bsd/Impl/ManagedSocket.cs @@ -323,9 +323,14 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd int value = optionValue.Length >= 4 ? MemoryMarshal.Read(optionValue) : MemoryMarshal.Read(optionValue); - if (option == BsdSocketOption.SoLinger) + if (level == SocketOptionLevel.Socket && option == BsdSocketOption.SoLinger) { - int value2 = MemoryMarshal.Read(optionValue[4..]); + int value2 = 0; + + if (optionValue.Length >= 8) + { + value2 = MemoryMarshal.Read(optionValue[4..]); + } Socket.SetSocketOption(level, SocketOptionName.Linger, new LingerOption(value != 0, value2)); }