summaryrefslogtreecommitdiff
path: root/plugins/dfinput
diff options
context:
space:
mode:
authorStelios Tsampas <loathingkernel@gmail.com>2017-07-20 13:04:40 +0300
committerStelios Tsampas <loathingkernel@gmail.com>2017-07-20 13:04:40 +0300
commitdb51fade6de9461e7a139da2bf5887a9a6569506 (patch)
treef43878331e9abfd4f214cf60a06162854e4b75b3 /plugins/dfinput
parentb6129143f75cf4480883e467d52627de949466fb (diff)
downloadpcsxr-db51fade6de9461e7a139da2bf5887a9a6569506.tar.gz
* dfinput: Fix possible buffer overflows in the ui.
Diffstat (limited to 'plugins/dfinput')
-rwxr-xr-xplugins/dfinput/cfg-gtk.c4
-rwxr-xr-xplugins/dfinput/pad.c18
-rwxr-xr-xplugins/dfinput/sdljoy.c2
-rwxr-xr-xplugins/dfinput/xkb.c4
4 files changed, 17 insertions, 11 deletions
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 <sys/types.h>
+#include <sys/wait.h>
+#if !SDL_VERSION_ATLEAST(2,0,0)
#include <linux/input.h>
#include <sys/file.h>
#include <time.h>
#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);
}