[PATCH] dix: don't allow more than MAX_VALUATORS on one device.

Peter Hutterer peter.hutterer at who-t.net
Thu Apr 16 18:45:39 PDT 2009


Some keyboards (?) advertise more than MAX_VALUATORS axes. Parts of the
internal event delivery relies on not having more than MAX_VALUATOR axes, so
let's cap it down.
If there's real devices that require more than the current 36, I'm sure we can
bump this up.

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

This gave me a beautiful memory corruption on my xi2 branch, due to my
keyboard advertising 37 axes and evdev happily initializing all of them.

 Xi/exevents.c |    2 ++
 dix/devices.c |    8 ++++++++
 2 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/Xi/exevents.c b/Xi/exevents.c
index cfae57d..3f531d9 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1037,6 +1037,8 @@ InitValuatorAxisStruct(DeviceIntPtr dev, int axnum, int minval, int maxval,
 
     if (!dev || !dev->valuator || minval > maxval)
         return;
+    if (axnum >= dev->valuator->numAxes)
+        return;
 
     ax = dev->valuator->axes + axnum;
 
diff --git a/dix/devices.c b/dix/devices.c
index d14eddd..9f56842 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -1081,6 +1081,14 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes,
     if (!dev)
         return FALSE;
 
+    if (numAxes >= MAX_VALUATORS)
+    {
+        LogMessage(X_WARNING,
+                   "Device '%s' has %d axes, only using first %d.\n",
+                   dev->name, numAxes, MAX_VALUATORS);
+        numAxes = MAX_VALUATORS;
+    }
+
     valc = (ValuatorClassPtr)xcalloc(1, sizeof(ValuatorClassRec) +
 				    numAxes * sizeof(AxisInfo) +
 				    numAxes * sizeof(unsigned int));
-- 
1.6.2.2.447.g4afa7


More information about the xorg-devel mailing list