dix: avoid NULL-pointer dereference on button-only devices (#38313)

Submitted by Peter Hutterer on Feb. 22, 2012, 5:49 a.m.

Details

Message ID 20120222054955.GA30206@yabbi.bne.redhat.com
State Accepted
Commit 2416ee4a015068359807a10f433e8c54192c78a9
Headers show

Not browsing as part of any series.

Commit Message

Peter Hutterer Feb. 22, 2012, 5:49 a.m.
And for such devices simply take the last.valuators[] which must be valid at
all times anyway. UpdateSlaveDeviceCoords takes care of that.

X.Org Bug 38313 <http://bugs.freedesktop.org/show_bug.cgi?id=38313>

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
---
 dix/getevents.c |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/dix/getevents.c b/dix/getevents.c
index 6ea4ba0..306d0ff 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -840,10 +840,15 @@  scale_to_desktop(DeviceIntPtr dev, ValuatorMask *mask,
     ScreenPtr scr = miPointerGetScreen(dev);
     double x, y;
 
-    BUG_WARN(!dev->valuator);
-    BUG_WARN(dev->valuator->numAxes < 2);
+    BUG_WARN(!dev->valuator || dev->valuator->numAxes < 2);
     if (!dev->valuator || dev->valuator->numAxes < 2)
+    {
+        /* if we have no axes, last.valuators must be in screen coords
+         * anyway */
+        *devx = *screenx = dev->last.valuators[0];
+        *devy = *screeny = dev->last.valuators[1];
         return scr;
+    }
 
     if (valuator_mask_isset(mask, 0))
         x = valuator_mask_get_double(mask, 0);
@@ -1493,8 +1498,6 @@  GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
 {
     CARD32 ms = GetTimeInMillis();
     int num_events = 0, nev_tmp;
-    int h_scroll_axis = pDev->valuator->h_scroll_axis;
-    int v_scroll_axis = pDev->valuator->v_scroll_axis;
     ValuatorMask mask;
     ValuatorMask scroll;
     int i;
@@ -1519,6 +1522,14 @@  GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type,
     {
         double val, adj;
         int axis;
+        int h_scroll_axis = -1;
+        int v_scroll_axis = -1;
+
+        if (pDev->valuator)
+        {
+            h_scroll_axis = pDev->valuator->h_scroll_axis;
+            v_scroll_axis = pDev->valuator->v_scroll_axis;
+        }
 
         /* Up is negative on valuators, down positive */
         switch (buttons) {

Comments

On 02/21/2012 09:49 PM, Peter Hutterer wrote:
> And for such devices simply take the last.valuators[] which must be valid at
> all times anyway. UpdateSlaveDeviceCoords takes care of that.
> 
> X.Org Bug 38313 <http://bugs.freedesktop.org/show_bug.cgi?id=38313>
> 
> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>

Makes sense and looks right to me.

Reviewed-by: Chase Douglas <chase.douglas@canonical.com>