From 472119c8da7edaf7bf60fa75e87812e5cb16e33b Mon Sep 17 00:00:00 2001 From: Ac_K Date: Mon, 28 Nov 2022 02:53:57 +0100 Subject: [PATCH] sfdnsres; Fix deserializer of AddrInfoSerialized when addresses are empty (#3924) --- Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/IResolver.cs | 8 ++++---- .../HOS/Services/Sockets/Sfdnsres/Types/AddrInfo4.cs | 1 + .../Sockets/Sfdnsres/Types/AddrInfoSerialized.cs | 9 ++++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/IResolver.cs b/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/IResolver.cs index dd45e9ea6..80339b4ac 100644 --- a/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/IResolver.cs +++ b/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/IResolver.cs @@ -566,7 +566,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres private static List DeserializeAddrInfos(IVirtualMemoryManager memory, ulong address, ulong size) { - List result = new List(); + List result = new(); ReadOnlySpan data = memory.GetSpan(address, (int)size); @@ -606,9 +606,9 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres } // NOTE: 0 = Any - AddrInfoSerializedHeader header = new AddrInfoSerializedHeader(ip, 0); - AddrInfo4 addr = new AddrInfo4(ip, (short)port); - AddrInfoSerialized info = new AddrInfoSerialized(header, addr, null, hostEntry.HostName); + AddrInfoSerializedHeader header = new(ip, 0); + AddrInfo4 addr = new(ip, (short)port); + AddrInfoSerialized info = new(header, addr, null, hostEntry.HostName); data = info.Write(data); } diff --git a/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/AddrInfo4.cs b/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/AddrInfo4.cs index 19b570e49..0a20e0572 100644 --- a/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/AddrInfo4.cs +++ b/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/AddrInfo4.cs @@ -14,6 +14,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres.Types public byte Family; public short Port; public Array4 Address; + public Array8 Padding; public AddrInfo4(IPAddress address, short port) { diff --git a/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/AddrInfoSerialized.cs b/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/AddrInfoSerialized.cs index 470123967..a0613d7bc 100644 --- a/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/AddrInfoSerialized.cs +++ b/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Types/AddrInfoSerialized.cs @@ -35,7 +35,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres.Types AddrInfo4? socketAddress = null; Array4? rawIPv4Address = null; - string canonicalName = null; + string canonicalName; buffer = buffer[Unsafe.SizeOf()..]; @@ -50,6 +50,13 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres.Types Debug.Assert(header.Magic == SfdnsresContants.AddrInfoMagic); + if (header.AddressLength == 0) + { + rest = buffer; + + return null; + } + if (header.Family == (int)AddressFamily.InterNetwork) { socketAddress = MemoryMarshal.Read(buffer);