[PATCH 5/7] dinput: Check for DIEFF_POLAR axes count before capacity.

Rémi Bernon rbernon at codeweavers.com
Wed Nov 10 03:52:26 CST 2021


Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51922
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/dinput/joystick_hid.c | 4 ++--
 dlls/dinput8/tests/hid.c   | 6 +-----
 2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c
index dd77f557e3e..cec02ccd74a 100644
--- a/dlls/dinput/joystick_hid.c
+++ b/dlls/dinput/joystick_hid.c
@@ -2063,14 +2063,14 @@ static HRESULT WINAPI hid_joystick_effect_GetParameters( IDirectInputEffect *ifa
         if (!direction_flags) return DIERR_INVALIDPARAM;
 
         count = params->cAxes = impl->params.cAxes;
-        if (capacity < params->cAxes) return DIERR_MOREDATA;
         if (!count) params->dwFlags &= ~(DIEFF_CARTESIAN | DIEFF_POLAR | DIEFF_SPHERICAL);
+        if ((direction_flags & DIEFF_POLAR) && count != 2) return DIERR_INVALIDPARAM;
+        if (capacity < params->cAxes) return DIERR_MOREDATA;
 
         if (direction_flags & DIEFF_SPHERICAL)
             memcpy( directions, impl->params.rglDirection, count * sizeof(LONG) );
         else if (direction_flags & DIEFF_POLAR)
         {
-            if (count != 2) return DIERR_INVALIDPARAM;
             directions[0] = (impl->params.rglDirection[0] + 9000) % 36000;
             if (directions[0] < 0) directions[0] += 36000;
         }
diff --git a/dlls/dinput8/tests/hid.c b/dlls/dinput8/tests/hid.c
index 54109593a18..5b01ea3a68a 100644
--- a/dlls/dinput8/tests/hid.c
+++ b/dlls/dinput8/tests/hid.c
@@ -6138,11 +6138,7 @@ static void test_periodic_effect( IDirectInputDevice8W *device, HANDLE file, DWO
         desc.dwFlags = DIEFF_POLAR;
         desc.cAxes = 1;
         hr = IDirectInputEffect_GetParameters( effect, &desc, DIEP_DIRECTION );
-        if (i != 2)
-        {
-            todo_wine_if( i == 3 )
-            ok( hr == DIERR_INVALIDPARAM, "GetParameters returned %#x\n", hr );
-        }
+        if (i != 2) ok( hr == DIERR_INVALIDPARAM, "GetParameters returned %#x\n", hr );
         else ok( hr == DIERR_MOREDATA, "GetParameters returned %#x\n", hr );
         desc.cAxes = 3;
         memset( desc.rglDirection, 0xcd, 3 * sizeof(LONG) );
-- 
2.33.1




More information about the wine-devel mailing list