Fixed bug 4910 - Missing joystick-driver type check in haptic meyraud705 On Linux and MacOS, some haptic system functions access joystick->hw_data without checking the driver type.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
diff --git a/src/haptic/darwin/SDL_syshaptic.c b/src/haptic/darwin/SDL_syshaptic.c
index 65708cd..650a5e8 100644
--- a/src/haptic/darwin/SDL_syshaptic.c
+++ b/src/haptic/darwin/SDL_syshaptic.c
@@ -599,6 +599,9 @@ SDL_SYS_HapticMouse(void)
int
SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
{
+ if (joystick->driver != &SDL_DARWIN_JoystickDriver) {
+ return SDL_FALSE;
+ }
if (joystick->hwdata->ffservice != 0) {
return SDL_TRUE;
}
@@ -612,6 +615,9 @@ SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
int
SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
{
+ if (joystick->driver != &SDL_DARWIN_JoystickDriver) {
+ return 0;
+ }
if (IOObjectIsEqualTo((io_object_t) ((size_t)haptic->hwdata->device),
joystick->hwdata->ffservice)) {
return 1;
@@ -628,7 +634,10 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
{
int device_index = 0;
SDL_hapticlist_item *item;
-
+
+ if (joystick->driver != &SDL_DARWIN_JoystickDriver) {
+ return -1;
+ }
for (item = SDL_hapticlist; item; item = item->next) {
if (IOObjectIsEqualTo((io_object_t) item->dev,
joystick->hwdata->ffservice)) {
diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c
index 1924bf4..3a10323 100644
--- a/src/haptic/linux/SDL_syshaptic.c
+++ b/src/haptic/linux/SDL_syshaptic.c
@@ -512,6 +512,9 @@ SDL_SYS_HapticMouse(void)
int
SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
{
+ if (joystick->driver != &SDL_LINUX_JoystickDriver) {
+ return 0;
+ }
return EV_IsHaptic(joystick->hwdata->fd);
}
@@ -522,6 +525,9 @@ SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
int
SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
{
+ if (joystick->driver != &SDL_LINUX_JoystickDriver) {
+ return 0;
+ }
/* We are assuming Linux is using evdev which should trump the old
* joystick methods. */
if (SDL_strcmp(joystick->hwdata->fname, haptic->hwdata->fname) == 0) {
@@ -541,7 +547,10 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
int fd;
int ret;
SDL_hapticlist_item *item;
-
+
+ if (joystick->driver != &SDL_LINUX_JoystickDriver) {
+ return -1;
+ }
/* Find the joystick in the haptic list. */
for (item = SDL_hapticlist; item; item = item->next) {
if (SDL_strcmp(item->fname, joystick->hwdata->fname) == 0) {