From 9575a7638a8cab5772d5b536aead42a990a05222 Mon Sep 17 00:00:00 2001 From: Ac_K Date: Wed, 14 Apr 2021 14:47:19 +0200 Subject: [PATCH] nsd/ssl: Fix Resolve/ResolveEx and stub GetConnectionCount (#2208) --- .../HOS/Services/Sockets/Nsd/IManager.cs | 21 ++++++++++++++++--- .../Sockets/Nsd/Manager/FqdnResolver.cs | 2 +- .../Services/Ssl/SslService/ISslConnection.cs | 7 ++++++- .../Services/Ssl/SslService/ISslContext.cs | 15 +++++++++++++ 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/Ryujinx.HLE/HOS/Services/Sockets/Nsd/IManager.cs b/Ryujinx.HLE/HOS/Services/Sockets/Nsd/IManager.cs index e44d7270..f6b83eaa 100644 --- a/Ryujinx.HLE/HOS/Services/Sockets/Nsd/IManager.cs +++ b/Ryujinx.HLE/HOS/Services/Sockets/Nsd/IManager.cs @@ -1,4 +1,5 @@ using Ryujinx.Common.Logging; +using Ryujinx.Cpu; using Ryujinx.HLE.Exceptions; using Ryujinx.HLE.HOS.Services.Settings; using Ryujinx.HLE.HOS.Services.Sockets.Nsd.Manager; @@ -135,9 +136,16 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd long outputPosition = context.Request.ReceiveBuff[0].Position; long outputSize = context.Request.ReceiveBuff[0].Size; - ResultCode result = _fqdnResolver.ResolveEx(context, out ResultCode errorCode, out string resolvedAddress); + ResultCode result = _fqdnResolver.ResolveEx(context, out _, out string resolvedAddress); - byte[] resolvedAddressBuffer = Encoding.UTF8.GetBytes(resolvedAddress + '\0'); + if (resolvedAddress.Length > outputSize) + { + return ResultCode.InvalidArgument; + } + + byte[] resolvedAddressBuffer = Encoding.UTF8.GetBytes(resolvedAddress); + + MemoryHelper.FillWithZeros(context.Memory, outputPosition, (int)outputSize); context.Memory.Write((ulong)outputPosition, resolvedAddressBuffer); @@ -153,7 +161,14 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd ResultCode result = _fqdnResolver.ResolveEx(context, out ResultCode errorCode, out string resolvedAddress); - byte[] resolvedAddressBuffer = Encoding.UTF8.GetBytes(resolvedAddress + '\0'); + if (resolvedAddress.Length > outputSize) + { + return ResultCode.InvalidArgument; + } + + byte[] resolvedAddressBuffer = Encoding.UTF8.GetBytes(resolvedAddress); + + MemoryHelper.FillWithZeros(context.Memory, outputPosition, (int)outputSize); context.Memory.Write((ulong)outputPosition, resolvedAddressBuffer); diff --git a/Ryujinx.HLE/HOS/Services/Sockets/Nsd/Manager/FqdnResolver.cs b/Ryujinx.HLE/HOS/Services/Sockets/Nsd/Manager/FqdnResolver.cs index 0c5dac17..6bdf06ad 100644 --- a/Ryujinx.HLE/HOS/Services/Sockets/Nsd/Manager/FqdnResolver.cs +++ b/Ryujinx.HLE/HOS/Services/Sockets/Nsd/Manager/FqdnResolver.cs @@ -104,7 +104,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd.Manager context.Memory.Read((ulong)inputPosition, addressBuffer); - string address = Encoding.UTF8.GetString(addressBuffer); + string address = Encoding.UTF8.GetString(addressBuffer).TrimEnd('\0'); resultCode = Resolve(context, address, out resolvedAddress); diff --git a/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslConnection.cs b/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslConnection.cs index 76a61eed..9d1ffe85 100644 --- a/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslConnection.cs +++ b/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslConnection.cs @@ -78,7 +78,12 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.SslService long inputDataPosition = context.Request.SendBuff[0].Position; long inputDataSize = context.Request.SendBuff[0].Size; - uint transferredSize = 0; + byte[] data = new byte[inputDataSize]; + + context.Memory.Read((ulong)inputDataPosition, data); + + // NOTE: Tell the guest everything is transferred. + uint transferredSize = (uint)inputDataSize; context.ResponseData.Write(transferredSize); diff --git a/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslContext.cs b/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslContext.cs index 46fda4d8..ec4b5112 100644 --- a/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslContext.cs +++ b/Ryujinx.HLE/HOS/Services/Ssl/SslService/ISslContext.cs @@ -6,6 +6,8 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.SslService { class ISslContext : IpcService { + private uint _connectionCount; + private ulong _serverCertificateId; private ulong _clientCertificateId; @@ -17,6 +19,19 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.SslService { MakeObject(context, new ISslConnection()); + _connectionCount++; + + return ResultCode.Success; + } + + [CommandHipc(3)] + // GetConnectionCount() -> u32 count + public ResultCode GetConnectionCount(ServiceCtx context) + { + context.ResponseData.Write(_connectionCount); + + Logger.Stub?.PrintStub(LogClass.ServiceSsl, new { _connectionCount }); + return ResultCode.Success; }