aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTSRBerry <20988865+TSRBerry@users.noreply.github.com>2023-08-10 05:29:15 +0200
committerGitHub <noreply@github.com>2023-08-10 00:29:15 -0300
commitfe15c77d30b94a8b720b520dcacf39a0c832d58f (patch)
treebe85b986eee34ca878efeeb5c857a4ddb1b7ffb9
parent5e9678c8fad4625026268e457f4c3e23bdc22697 (diff)
[Hotfix] hid: Prevent out of bounds array access (#5547)1.1.979
* hid: Prevent out of bounds array access * Cast player to uint * Replace lambda function with local function
-rw-r--r--src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/NpadDevices.cs5
-rw-r--r--src/Ryujinx.Tests/Cpu/EnvironmentTests.cs33
2 files changed, 22 insertions, 16 deletions
diff --git a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/NpadDevices.cs b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/NpadDevices.cs
index 240933ad..86c6a825 100644
--- a/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/NpadDevices.cs
+++ b/src/Ryujinx.HLE/HOS/Services/Hid/HidDevices/NpadDevices.cs
@@ -70,6 +70,11 @@ namespace Ryujinx.HLE.HOS.Services.Hid
internal void SetSupportedPlayer(PlayerIndex player, bool supported = true)
{
+ if ((uint)player >= _supportedPlayers.Length)
+ {
+ return;
+ }
+
_supportedPlayers[(int)player] = supported;
}
diff --git a/src/Ryujinx.Tests/Cpu/EnvironmentTests.cs b/src/Ryujinx.Tests/Cpu/EnvironmentTests.cs
index 1ef12de5..5e6b286b 100644
--- a/src/Ryujinx.Tests/Cpu/EnvironmentTests.cs
+++ b/src/Ryujinx.Tests/Cpu/EnvironmentTests.cs
@@ -48,7 +48,22 @@ namespace Ryujinx.Tests.Cpu
bool methodCalled = false;
bool isFz = false;
- var managedMethod = () =>
+ var method = TranslatorTestMethods.GenerateFpFlagsPInvokeTest();
+
+ // This method sets flush-to-zero and then calls the managed method.
+ // Before and after setting the flags, it ensures subnormal addition works as expected.
+ // It returns a positive result if any tests fail, and 0 on success (or if the platform cannot change FP flags)
+ int result = method(Marshal.GetFunctionPointerForDelegate(ManagedMethod));
+
+ // Subnormal results are not flushed to zero by default, which we should have returned to exiting the method.
+ Assert.AreNotEqual(GetDenormal() + GetZero(), 0f);
+
+ Assert.True(result == 0);
+ Assert.True(methodCalled);
+ Assert.True(isFz);
+ return;
+
+ void ManagedMethod()
{
// Floating point math should not modify fp flags.
float test = 2f * 3.5f;
@@ -73,21 +88,7 @@ namespace Ryujinx.Tests.Cpu
methodCalled = true;
}
- };
-
- var method = TranslatorTestMethods.GenerateFpFlagsPInvokeTest();
-
- // This method sets flush-to-zero and then calls the managed method.
- // Before and after setting the flags, it ensures subnormal addition works as expected.
- // It returns a positive result if any tests fail, and 0 on success (or if the platform cannot change FP flags)
- int result = method(Marshal.GetFunctionPointerForDelegate(managedMethod));
-
- // Subnormal results are not flushed to zero by default, which we should have returned to exiting the method.
- Assert.AreNotEqual(GetDenormal() + GetZero(), 0f);
-
- Assert.True(result == 0);
- Assert.True(methodCalled);
- Assert.True(isFz);
+ }
}
}
}