From db51fade6de9461e7a139da2bf5887a9a6569506 Mon Sep 17 00:00:00 2001 From: Stelios Tsampas Date: Thu, 20 Jul 2017 13:04:40 +0300 Subject: * dfinput: Fix possible buffer overflows in the ui. --- plugins/dfinput/cfg-gtk.c | 4 ++-- plugins/dfinput/pad.c | 18 ++++++++++++------ plugins/dfinput/sdljoy.c | 2 +- plugins/dfinput/xkb.c | 4 ++-- 4 files changed, 17 insertions(+), 11 deletions(-) (limited to 'plugins/dfinput') diff --git a/plugins/dfinput/cfg-gtk.c b/plugins/dfinput/cfg-gtk.c index 6d053af7..bcc733d1 100755 --- a/plugins/dfinput/cfg-gtk.c +++ b/plugins/dfinput/cfg-gtk.c @@ -624,9 +624,9 @@ static void PopulateDevList() { for (j = 0; j < n; j++) { #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_Joystick *joystick = SDL_JoystickOpen(j); - sprintf(buf, "%d: %s", j + 1, SDL_JoystickName(joystick)); + snprintf(buf, sizeof(buf), "%d: %s", j + 1, SDL_JoystickName(joystick)); #else - sprintf(buf, "%d: %s", j + 1, SDL_JoystickName(j)); + snprintf(buf, sizeof(buf), "%d: %s", j + 1, SDL_JoystickName(j)); #endif gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, 0, buf, -1); diff --git a/plugins/dfinput/pad.c b/plugins/dfinput/pad.c index bd3aef73..8861ec4d 100755 --- a/plugins/dfinput/pad.c +++ b/plugins/dfinput/pad.c @@ -17,11 +17,15 @@ */ #include "pad.h" -#if !SDL_VERSION_ATLEAST(2,0,0) && defined(__linux__) +#if defined(__linux__) +#include +#include +#if !SDL_VERSION_ATLEAST(2,0,0) #include #include #include #endif +#endif #if SDL_VERSION_ATLEAST(2,0,0) int has_haptic; @@ -121,11 +125,13 @@ long PADopen(unsigned long *Disp) { } #if SDL_VERSION_ATLEAST(2,0,0) - SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER); - - has_haptic = 0; - if (SDL_InitSubSystem(SDL_INIT_HAPTIC) == 0) - has_haptic = 1; + SDL_QuitSubSystem(SDL_INIT_JOYSTICK); + if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == -1) + return PSE_PAD_ERR_FAILURE; + + has_haptic = 0; + if (SDL_InitSubSystem(SDL_INIT_HAPTIC) == 0) + has_haptic = 1; #endif InitSDLJoy(); diff --git a/plugins/dfinput/sdljoy.c b/plugins/dfinput/sdljoy.c index d9bc23a3..3e8cc993 100755 --- a/plugins/dfinput/sdljoy.c +++ b/plugins/dfinput/sdljoy.c @@ -74,7 +74,7 @@ int JoyHapticRumble(int pad, uint32_t low, uint32_t high) if(SDL_HapticRumblePlay(g.PadState[pad].haptic, mag, 500) != 0) { - printf("\nFailed to play rumble: %s\n", SDL_GetError()); + printf("\nFailed to play rumble on pad %d with error: %s\n", pad, SDL_GetError()); return 1; } } diff --git a/plugins/dfinput/xkb.c b/plugins/dfinput/xkb.c index 53fb90d4..47eac669 100755 --- a/plugins/dfinput/xkb.c +++ b/plugins/dfinput/xkb.c @@ -46,7 +46,7 @@ void InitKeyboard() { resumeScrSaver = 0; if (g.cfg.PreventScrSaver) { char buf[64]; - snprintf(buf, 64, "xdg-screensaver suspend 0x%x > /dev/null 2>&1", window); + snprintf(buf, sizeof(buf), "xdg-screensaver suspend 0x%x > /dev/null 2>&1", window); if (pclose(popen(buf, "r")) == 0) { resumeScrSaver = 1; printf("Suspending Window ID 0x%x of activating screensaver.\n", window); @@ -79,7 +79,7 @@ void DestroyKeyboard() { if (resumeScrSaver) { char buf[64]; printf("Resuming Window ID 0x%x to activate screensaver.\n", window); - snprintf(buf, 64, "xdg-screensaver resume 0x%x", window); + snprintf(buf, sizeof(buf), "xdg-screensaver resume 0x%x", window); FILE *phandle = popen(buf, "r"); pclose(phandle); } -- cgit v1.2.3