From 51fa1b2cb0bb54c0eb235c9d1fa68a7e1abaf464 Mon Sep 17 00:00:00 2001 From: Mary Date: Mon, 25 Oct 2021 00:13:20 +0200 Subject: hle: Improve safety (#2778) * timezone: Make timezone implementation safe * hle: Do not use TrimEnd to parse ASCII strings This adds an util that handle reading an ASCII string in a safe way. Previously it was possible to read malformed data that could cause various undefined behaviours in multiple services. * hid: Remove an useless unsafe modifier on keyboard update * Address gdkchan's comment * Address gdkchan's comment --- Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/IResolver.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'Ryujinx.HLE/HOS/Services/Sockets') diff --git a/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/IResolver.cs b/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/IResolver.cs index 2baeb1ef..06df4d13 100644 --- a/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/IResolver.cs +++ b/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/IResolver.cs @@ -218,11 +218,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres private ResultCode GetHostByNameRequestImpl(ServiceCtx context, ulong inputBufferPosition, ulong inputBufferSize, ulong outputBufferPosition, ulong outputBufferSize, ulong optionsBufferPosition, ulong optionsBufferSize) { - byte[] rawName = new byte[inputBufferSize]; - - context.Memory.Read(inputBufferPosition, rawName); - - string name = Encoding.ASCII.GetString(rawName).TrimEnd('\0'); + string name = MemoryHelper.ReadAsciiString(context.Memory, inputBufferPosition, (int)inputBufferSize); // TODO: Use params. bool enableNsdResolve = (context.RequestData.ReadInt32() & 1) != 0; -- cgit v1.2.3