From a4fdfb5f94121f5c60fc5717175fd21f3e774e85 Mon Sep 17 00:00:00 2001 From: gnisman Date: Mon, 26 Dec 2022 15:49:26 +0200 Subject: [PATCH] bsd::RecvFrom: verify output buffer size before writing socket address (#4135) * bsd::RecvFrom: Ryujinx does not verify output buffer size before writing socket address * Calculate the size of BsdSockAddr * use bsdSockAddr variable * Update Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs Co-authored-by: Mary-nyan * Update Ryujinx.HLE/HOS/Services/Sockets/Bsd/Types/BsdSockAddr.cs Co-authored-by: Mary-nyan * set errno to ENOMEM in case we can't write the address to memory * Update Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs Co-authored-by: Ac_K * Update Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs Co-authored-by: Mary-nyan Co-authored-by: Ac_K --- Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs b/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs index eaf65e4cca..bc174cce52 100644 --- a/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs +++ b/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs @@ -530,7 +530,14 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd receiveRegion.Dispose(); - context.Memory.Write(sockAddrOutPosition, BsdSockAddr.FromIPEndPoint(endPoint)); + if (sockAddrOutSize != 0 && sockAddrOutSize >= (ulong) Unsafe.SizeOf()) + { + context.Memory.Write(sockAddrOutPosition, BsdSockAddr.FromIPEndPoint(endPoint)); + } + else + { + errno = LinuxError.ENOMEM; + } } }