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.
This commit is contained in:
Sam Lantinga 2019-12-22 13:56:50 -08:00
parent f21e172767
commit 982f8a83ec
2 changed files with 20 additions and 2 deletions

View File

@ -599,6 +599,9 @@ SDL_SYS_HapticMouse(void)
int int
SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick) SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
{ {
if (joystick->driver != &SDL_DARWIN_JoystickDriver) {
return SDL_FALSE;
}
if (joystick->hwdata->ffservice != 0) { if (joystick->hwdata->ffservice != 0) {
return SDL_TRUE; return SDL_TRUE;
} }
@ -612,6 +615,9 @@ SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
int int
SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick) 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), if (IOObjectIsEqualTo((io_object_t) ((size_t)haptic->hwdata->device),
joystick->hwdata->ffservice)) { joystick->hwdata->ffservice)) {
return 1; return 1;
@ -629,6 +635,9 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
int device_index = 0; int device_index = 0;
SDL_hapticlist_item *item; SDL_hapticlist_item *item;
if (joystick->driver != &SDL_DARWIN_JoystickDriver) {
return -1;
}
for (item = SDL_hapticlist; item; item = item->next) { for (item = SDL_hapticlist; item; item = item->next) {
if (IOObjectIsEqualTo((io_object_t) item->dev, if (IOObjectIsEqualTo((io_object_t) item->dev,
joystick->hwdata->ffservice)) { joystick->hwdata->ffservice)) {

View File

@ -512,6 +512,9 @@ SDL_SYS_HapticMouse(void)
int int
SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick) SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
{ {
if (joystick->driver != &SDL_LINUX_JoystickDriver) {
return 0;
}
return EV_IsHaptic(joystick->hwdata->fd); return EV_IsHaptic(joystick->hwdata->fd);
} }
@ -522,6 +525,9 @@ SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
int int
SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick) 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 /* We are assuming Linux is using evdev which should trump the old
* joystick methods. */ * joystick methods. */
if (SDL_strcmp(joystick->hwdata->fname, haptic->hwdata->fname) == 0) { if (SDL_strcmp(joystick->hwdata->fname, haptic->hwdata->fname) == 0) {
@ -542,6 +548,9 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
int ret; int ret;
SDL_hapticlist_item *item; SDL_hapticlist_item *item;
if (joystick->driver != &SDL_LINUX_JoystickDriver) {
return -1;
}
/* Find the joystick in the haptic list. */ /* Find the joystick in the haptic list. */
for (item = SDL_hapticlist; item; item = item->next) { for (item = SDL_hapticlist; item; item = item->next) {
if (SDL_strcmp(item->fname, joystick->hwdata->fname) == 0) { if (SDL_strcmp(item->fname, joystick->hwdata->fname) == 0) {