Fixed bug 1337 - joystick crash due to heap corruption with btnx SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Sun, 01 Jan 2012 16:55:06 -0500
branchSDL-1.2
changeset 6144 20d04c674a08
parent 6143 29811864f4cf
child 6146 06ae169343e4
Fixed bug 1337 - joystick crash due to heap corruption with btnx
src/joystick/SDL_joystick.c
--- a/src/joystick/SDL_joystick.c	Sun Jan 01 11:18:03 2012 -0500
+++ b/src/joystick/SDL_joystick.c	Sun Jan 01 16:55:06 2012 -0500
@@ -433,6 +433,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;
 
@@ -458,6 +463,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;
 
@@ -484,6 +494,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;