From 1b548a8af928107a328881a79debb33ef5a80653 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Tue, 7 Aug 2018 10:10:02 +0300 Subject: [PATCH] linux/SDL_sysjoystick.c: Fix bug #3193: Protect against any axis that isn't reported by EVIOCGBIT but still sends EV_ABS events; patch from . Original issue and description: The Dualshock 3's motion sensors don't seem to be reported by the call to EVIOCGBIT but they still send EV_ABS events. Because they're not reported by EVIOCGBIT they're not assigned a proper axis ids and the default of 0 is used, which is the valid id for the left analog sticks left/right axis. The attached patch sets the default axis id to ABS_MAX and then checks the axis id before performing the update. This will protect against EV_ABS events for axes that aren't reported or handled correctly. --- src/joystick/linux/SDL_sysjoystick.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index f5f0d2f58..7acdaf0f0 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -826,6 +826,9 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) return(-1); } SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); +#if SDL_INPUT_LINUXEV + SDL_memset(joystick->hwdata->abs_map, ABS_MAX, sizeof(*joystick->hwdata->abs_map)*ABS_MAX); +#endif joystick->hwdata->fd = fd; /* Set the joystick to non-blocking read mode */ @@ -1123,15 +1126,17 @@ static __inline__ void EV_HandleEvents(SDL_Joystick *joystick) events[i].value); break; default: - events[i].value = EV_AxisCorrect(joystick, code, events[i].value); + if (joystick->hwdata->abs_map[code] != ABS_MAX ) { + events[i].value = EV_AxisCorrect(joystick, code, events[i].value); #ifndef NO_LOGICAL_JOYSTICKS - if (!LogicalJoystickAxis(joystick, + if (!LogicalJoystickAxis(joystick, joystick->hwdata->abs_map[code], events[i].value)) #endif - SDL_PrivateJoystickAxis(joystick, + SDL_PrivateJoystickAxis(joystick, joystick->hwdata->abs_map[code], events[i].value); + } break; } break;