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 614420d04c674a08
parent 6143 29811864f4cf
child 6146 06ae169343e4
Fixed bug 1337 - joystick crash due to heap corruption with btnx
src/joystick/SDL_joystick.c
     1.1 --- a/src/joystick/SDL_joystick.c	Sun Jan 01 11:18:03 2012 -0500
     1.2 +++ b/src/joystick/SDL_joystick.c	Sun Jan 01 16:55:06 2012 -0500
     1.3 @@ -433,6 +433,11 @@
     1.4  {
     1.5  	int posted;
     1.6  
     1.7 +	/* Make sure we're not getting garbage events */
     1.8 +	if (axis >= joystick->naxes) {
     1.9 +		return 0;
    1.10 +	}
    1.11 +
    1.12  	/* Update internal joystick state */
    1.13  	joystick->axes[axis] = value;
    1.14  
    1.15 @@ -458,6 +463,11 @@
    1.16  {
    1.17  	int posted;
    1.18  
    1.19 +	/* Make sure we're not getting garbage events */
    1.20 +	if (hat >= joystick->nhats) {
    1.21 +		return 0;
    1.22 +	}
    1.23 +
    1.24  	/* Update internal joystick state */
    1.25  	joystick->hats[hat] = value;
    1.26  
    1.27 @@ -484,6 +494,11 @@
    1.28  {
    1.29  	int posted;
    1.30  
    1.31 +	/* Make sure we're not getting garbage events */
    1.32 +	if (ball >= joystick->nballs) {
    1.33 +		return 0;
    1.34 +	}
    1.35 +
    1.36  	/* Update internal mouse state */
    1.37  	joystick->balls[ball].dx += xrel;
    1.38  	joystick->balls[ball].dy += yrel;
    1.39 @@ -526,6 +541,11 @@
    1.40  	}
    1.41  #endif /* !SDL_EVENTS_DISABLED */
    1.42  
    1.43 +	/* Make sure we're not getting garbage events */
    1.44 +	if (button >= joystick->nbuttons) {
    1.45 +		return 0;
    1.46 +	}
    1.47 +
    1.48  	/* Update internal joystick state */
    1.49  	joystick->buttons[button] = state;
    1.50