[PATCH] Xi: check for NULL pointer before dereferences it in ListButtonInfo

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


On Mon, Apr 19, 2010 at 08:58:03PM +0300, Tiago Vignatti wrote:
> Both dev and dev->button are already used before their checking were being
> performed. So check on the beginning.
> 
> Signed-off-by: Tiago Vignatti <tiago.vignatti at nokia.com>
> ---
>  Xi/xiquerydevice.c |    5 ++++-
>  1 files changed, 4 insertions(+), 1 deletions(-)
> 
> diff --git a/Xi/xiquerydevice.c b/Xi/xiquerydevice.c
> index 435868d..47ab688 100644
> --- a/Xi/xiquerydevice.c
> +++ b/Xi/xiquerydevice.c
> @@ -247,6 +247,9 @@ ListButtonInfo(DeviceIntPtr dev, xXIButtonInfo* info, Bool reportState)
>      int mask_len;
>      int i;
>  
> +    if (!dev || !dev->button)
> +	return 0;
> +
>      mask_len = bytes_to_int32(bits_to_bytes(dev->button->numButtons));
>  
>      info->type = ButtonClass;
> @@ -259,7 +262,7 @@ ListButtonInfo(DeviceIntPtr dev, xXIButtonInfo* info, Bool reportState)
>      memset(bits, 0, mask_len * 4);
>  
>      if (reportState)
> -	for (i = 0; dev && dev->button && i < dev->button->numButtons; i++)
> +	for (i = 0; i < dev->button->numButtons; i++)
>  	    if (BitIsOn(dev->button->down, i))
>  		SetBit(bits, i);
>  
> -- 
> 1.6.0.4

Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>

rather superfluous given the checks by the callers, but..

Cheers,
  Peter


More information about the xorg-devel mailing list