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

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


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..a4bbc2e 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 BadValue;
+
     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



More information about the xorg-devel mailing list