Fixed bug 1337 - joystick crash due to heap corruption with btnx
authorSam Lantinga <slouken@libsdl.org>
Sun, 01 Jan 2012 16:58:00 -0500
changeset 6145 964d13f789e2
parent 6140 67268d47c17b
child 6148 36f5d9fc9c39
Fixed bug 1337 - joystick crash due to heap corruption with btnx
src/joystick/SDL_joystick.c
--- a/src/joystick/SDL_joystick.c	Sat Dec 31 13:29:09 2011 -0500
+++ b/src/joystick/SDL_joystick.c	Sun Jan 01 16:58:00 2012 -0500
@@ -427,6 +427,11 @@
 {
     int posted;
 
+    /* Make sure we're not getting garbage events */
+    if (axis >= joystick->naxes) {
+        return 0;
+    }
+
     /* Update internal joystick state */
     joystick->axes[axis] = value;
 
@@ -454,6 +459,11 @@
 {
     int posted;
 
+    /* Make sure we're not getting garbage events */
+    if (hat >= joystick->nhats) {
+        return 0;
+    }
+
     /* Update internal joystick state */
     joystick->hats[hat] = value;
 
@@ -482,6 +492,11 @@
 {
     int posted;
 
+    /* Make sure we're not getting garbage events */
+    if (ball >= joystick->nballs) {
+        return 0;
+    }
+
     /* Update internal mouse state */
     joystick->balls[ball].dx += xrel;
     joystick->balls[ball].dy += yrel;
@@ -526,6 +541,11 @@
     }
 #endif /* !SDL_EVENTS_DISABLED */
 
+    /* Make sure we're not getting garbage events */
+    if (button >= joystick->nbuttons) {
+        return 0;
+    }
+
     /* Update internal joystick state */
     joystick->buttons[button] = state;