[PATCH] [xkb] Fix possible NULL dereference in XkbFlushLedEvents()

Peter Hutterer peter.hutterer at who-t.net
Sun Dec 6 17:14:13 PST 2009


On Sun, Dec 06, 2009 at 11:52:55PM +0100, Tomas Carnecky wrote:
> Through some code paths it is possible that NULL is being passed in the
> 'ed' parameter to XkbFlushLedEvents(). Make sure we don't pass it along
> to bzero().
> 
> Signed-off-by: Tomas Carnecky <tom at dbservice.com>
> ---
>  xkb/xkbLEDs.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/xkb/xkbLEDs.c b/xkb/xkbLEDs.c
> index 59cdba4..dfdd5a2 100644
> --- a/xkb/xkbLEDs.c
> +++ b/xkb/xkbLEDs.c
> @@ -750,7 +750,8 @@ XkbFlushLedEvents(	DeviceIntPtr			dev,
>  	    XkbDDXUpdateDeviceIndicators(dev,sli,sli->effectiveState);
>  	XkbSendExtensionDeviceNotify(dev,cause->client,ed);
>      }
> -    bzero((char *)ed,sizeof(XkbExtensionDeviceNotify));
> +    if (ed)
> +	bzero((char *)ed,sizeof(XkbExtensionDeviceNotify));
>      return;
>  }

given that the bzero man page claims it's deprecated this would be a good
time to replace it with memset.

given the previous condition, the final code after applying this patch would
look like this:

if (ed && ed->reason) {
        foo
}
if (ed)
        bzero(...);


A better flow would be:
if (ed) {
        if (ed->reason)
                foo
        bzero/memset(...):
}

Cheers,
  Peter


More information about the xorg-devel mailing list