55654aa
From 11eea736f44a236dde884b52ad51cb5d1271b7a5 Mon Sep 17 00:00:00 2001
55654aa
From: Peter Hutterer <peter.hutterer@who-t.net>
55654aa
Date: Wed, 13 Jan 2010 15:03:45 +1000
55654aa
Subject: [PATCH] Xi: reset the sli pointers after copying device classes. (#25640)
55654aa
55654aa
If the indicator flags have the XkbSLI_IsDefault bit set, the indicator map
55654aa
and names aren't their own bit of memory but rather point into the
55654aa
device->key->xkbInfo->desc structure. XkbCopySrvLedInfo knows about this and
55654aa
leaves the pointers alone.
55654aa
55654aa
When copying the classes from the slave to the master, these pointers are
55654aa
copied and still point to the dev->key class of the slave device. If the
55654aa
slave device is removed, the memory becomes invalid and a call to modify
55654aa
this data (e.g. XkbSetIndicators) may cause a deadlock.
55654aa
55654aa
The copying of dev->key relies on dev->kbdfeed to be already set up. Hence
55654aa
the pointers need to be reset once _both_ kbdfeed and key have been copied
55654aa
into the master device.
55654aa
55654aa
X.Org Bug 25640 <http://bugs.freedesktop.org/show_bug.cgi?id=25640>
55654aa
Fedora Bug 540584 <https://bugzilla.redhat.com/show_bug.cgi?id=540584>
55654aa
---
55654aa
 Xi/exevents.c |   20 ++++++++++++++++++++
55654aa
 1 files changed, 20 insertions(+), 0 deletions(-)
55654aa
55654aa
diff --git a/Xi/exevents.c b/Xi/exevents.c
55654aa
index cb2452b..ee32ba8 100644
55654aa
--- a/Xi/exevents.c
55654aa
+++ b/Xi/exevents.c
55654aa
@@ -444,6 +444,26 @@ DeepCopyKeyboardClasses(DeviceIntPtr from, DeviceIntPtr to)
55654aa
         to->key      = NULL;
55654aa
     }
55654aa
 
55654aa
+    /* If a SrvLedInfoPtr's flags are XkbSLI_IsDefault, the names and maps
55654aa
+     * pointer point into the xkbInfo->desc struct.  XkbCopySrvLedInfo
55654aa
+     * didn't update the pointers so we need to do it manually here.
55654aa
+     */
55654aa
+    if (to->kbdfeed)
55654aa
+    {
55654aa
+        KbdFeedbackPtr k;
55654aa
+
55654aa
+        for (k = to->kbdfeed; k; k = k->next)
55654aa
+        {
55654aa
+            if (!k->xkb_sli)
55654aa
+                continue;
55654aa
+            if (k->xkb_sli->flags & XkbSLI_IsDefault)
55654aa
+            {
55654aa
+                k->xkb_sli->names = to->key->xkbInfo->desc->names->indicators;
55654aa
+                k->xkb_sli->maps = to->key->xkbInfo->desc->indicators->maps;
55654aa
+            }
55654aa
+        }
55654aa
+    }
55654aa
+
55654aa
     /* We can't just copy over the focus class. When an app sets the focus,
55654aa
      * it'll do so on the master device. Copying the SDs focus means losing
55654aa
      * the focus.
55654aa
-- 
55654aa
1.6.6
55654aa