[PATCH] dix: use BUG_WARN for xi2mask size issues
Peter Hutterer
peter.hutterer at who-t.net
Tue Nov 8 21:15:38 PST 2011
Yes, we're likely corrupting memory here but really this is unlikely to be
triggered other than a real bug in the server. In which case a stacktrace is
going to be more useful than any silent error handling.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
dix/inpututils.c | 21 +++++++++++----------
1 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/dix/inpututils.c b/dix/inpututils.c
index 05d4c7c..7405794 100644
--- a/dix/inpututils.c
+++ b/dix/inpututils.c
@@ -972,8 +972,9 @@ xi2mask_isset(XI2Mask* mask, const DeviceIntPtr dev, int event_type)
{
int set = 0;
- if (dev->id < 0 || dev->id >= mask->nmasks || event_type >= mask->mask_size)
- return 0;
+ BUG_WARN(dev->id < 0);
+ BUG_WARN(dev->id >= mask->nmasks);
+ BUG_WARN(event_type >= mask->mask_size);
set = !!BitIsOn(mask->masks[XIAllDevices], event_type);
if (!set)
@@ -990,8 +991,9 @@ xi2mask_isset(XI2Mask* mask, const DeviceIntPtr dev, int event_type)
void
xi2mask_set(XI2Mask *mask, int deviceid, int event_type)
{
- if (deviceid < 0 || deviceid >= mask->nmasks || event_type >= mask->mask_size)
- return;
+ BUG_WARN(devicid < 0);
+ BUG_WARN(deviceid >= mask->nmasks);
+ BUG_WARN(event_type >= mask->mask_size);
SetBit(mask->masks[deviceid], event_type);
}
@@ -1005,8 +1007,7 @@ xi2mask_zero(XI2Mask *mask, int deviceid)
{
int i;
- if (deviceid > 0 && deviceid >= mask->nmasks)
- return;
+ BUG_WARN(deviceid > 0 && deviceid >= mask->nmasks);
if (deviceid >= 0)
memset(mask->masks[deviceid], 0, mask->mask_size);
@@ -1055,8 +1056,8 @@ xi2mask_mask_size(const XI2Mask *mask)
void
xi2mask_set_one_mask(XI2Mask *xi2mask, int deviceid, const unsigned char *mask, size_t mask_size)
{
- if (deviceid < 0 || deviceid >= xi2mask->nmasks)
- return;
+ BUG_WARN(deviceid < 0);
+ BUG_WARN(deviceid >= xi2mask->nmasks);
memcpy(xi2mask->masks[deviceid], mask, min(xi2mask->mask_size, mask_size));
}
@@ -1067,8 +1068,8 @@ xi2mask_set_one_mask(XI2Mask *xi2mask, int deviceid, const unsigned char *mask,
const unsigned char*
xi2mask_get_one_mask(const XI2Mask *mask, int deviceid)
{
- if (deviceid < 0 || deviceid >= mask->nmasks)
- return NULL;
+ BUG_WARN(deviceid < 0);
+ BUG_WARN(deviceid >= mask->nmasks);
return mask->masks[deviceid];
}
--
1.7.7
More information about the xorg-devel
mailing list