[PATCH] dix: check for NULL pointer before dereferences it in DeviceEnterLeaveEvent

Peter Hutterer peter.hutterer at who-t.net
Mon Apr 19 17:28:31 PDT 2010


On Mon, Apr 19, 2010 at 08:58:04PM +0300, Tiago Vignatti wrote:
> mouse is already used before its checking should be performed. So check on the
> beginning instead.
> ---
>  dix/events.c |    6 +++++-
>  1 files changed, 5 insertions(+), 1 deletions(-)
> 
> diff --git a/dix/events.c b/dix/events.c
> index 6541652..8bec8af 100644
> --- a/dix/events.c
> +++ b/dix/events.c
> @@ -4360,6 +4360,10 @@ DeviceEnterLeaveEvent(
>          (mode == XINotifyPassiveUngrab && type == XI_Enter))
>          return;
>  
> +    if (!mouse)
> +        return;
> +    grab = mouse->deviceGrab.grab;
> +

there's something missing here, the assignment is still there - 6 lines
above this hunk.

also, not really a big fan of this change, if mouse is NULL we have other
issues and I'd rather the server fails than be quiet about it. missing
enter/leave events are nasty to debug.

so if you just want to shut up coverity, remove all the mouse != NULL checks
here but leave the rest there a landmine.

Cheers,
  Peter

>      btlen = (mouse->button) ? bits_to_bytes(mouse->button->numButtons) : 0;
>      btlen = bytes_to_int32(btlen);
>      len = sizeof(xXIEnterEvent) + btlen * 4;
> @@ -4378,7 +4382,7 @@ DeviceEnterLeaveEvent(
>      event->root_x       = FP1616(mouse->spriteInfo->sprite->hot.x, 0);
>      event->root_y       = FP1616(mouse->spriteInfo->sprite->hot.y, 0);
>  
> -    for (i = 0; mouse && mouse->button && i < mouse->button->numButtons; i++)
> +    for (i = 0; mouse->button && i < mouse->button->numButtons; i++)
>          if (BitIsOn(mouse->button->down, i))
>              SetBit(&event[1], i);
>  
> -- 
> 1.6.0.4
 


More information about the xorg-devel mailing list