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 6145964d13f789e2
parent 6140 67268d47c17b
child 6148 36f5d9fc9c39
Fixed bug 1337 - joystick crash due to heap corruption with btnx
src/joystick/SDL_joystick.c
     1.1 --- a/src/joystick/SDL_joystick.c	Sat Dec 31 13:29:09 2011 -0500
     1.2 +++ b/src/joystick/SDL_joystick.c	Sun Jan 01 16:58:00 2012 -0500
     1.3 @@ -427,6 +427,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 @@ -454,6 +459,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 @@ -482,6 +492,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