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

Tiago Vignatti tiago.vignatti at nokia.com
Fri Apr 16 08:42:23 PDT 2010


Both mouse and mouse->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>
---
 dix/events.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/dix/events.c b/dix/events.c
index 6541652..f949b07 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -4350,7 +4350,7 @@ DeviceEnterLeaveEvent(
     WindowPtr pWin,
     Window child)
 {
-    GrabPtr             grab = mouse->deviceGrab.grab;
+    GrabPtr             grab;
     xXIEnterEvent       *event;
     int                 filter;
     int                 btlen, len, i;
@@ -4360,6 +4360,10 @@ DeviceEnterLeaveEvent(
         (mode == XINotifyPassiveUngrab && type == XI_Enter))
         return;
 
+    if (!mouse || !mouse->button)
+        return;
+    grab = mouse->deviceGrab.grab;
+
     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; 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