[PATCH v2 04/29] Core events: invert check for permission to copy key states

Alan Coopersmith alan.coopersmith at oracle.com
Wed Jul 4 15:37:18 PDT 2012


Always initialize to zero, and then if permission is granted, copy
the current key state maps.   Use memcpy instead of memmove for the
copy, since we're always copying to a newly allocated event on the
stack, so guaranteed not to overlap with the device map structure.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 dix/events.c |   18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/dix/events.c b/dix/events.c
index 7933749..6e4385a 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -4512,11 +4512,12 @@ CoreEnterLeaveEvent(DeviceIntPtr mouse,
     if ((type == EnterNotify) && (mask & KeymapStateMask)) {
         xKeymapEvent ke;
         ClientPtr client = grab ? rClient(grab) : wClient(pWin);
+        int rc;
 
-        if (XaceHook(XACE_DEVICE_ACCESS, client, keybd, DixReadAccess))
-            memset((char *) &ke.map[0], 0, 31);
-        else
-            memmove((char *) &ke.map[0], (char *) &keybd->key->down[1], 31);
+        memset((char *) &ke.map[0], 0, 31);
+        rc = XaceHook(XACE_DEVICE_ACCESS, client, keybd, DixReadAccess);
+        if (rc == Success)
+            memcpy((char *) &ke.map[0], (char *) &keybd->key->down[1], 31);
 
         ke.type = KeymapNotify;
         if (grab)
@@ -4617,11 +4618,12 @@ CoreFocusEvent(DeviceIntPtr dev, int type, int mode, int detail, WindowPtr pWin)
         ((pWin->eventMask | wOtherEventMasks(pWin)) & KeymapStateMask)) {
         xKeymapEvent ke;
         ClientPtr client = wClient(pWin);
+        int rc;
 
-        if (XaceHook(XACE_DEVICE_ACCESS, client, dev, DixReadAccess))
-            memset((char *) &ke.map[0], 0, 31);
-        else
-            memmove((char *) &ke.map[0], (char *) &dev->key->down[1], 31);
+        memset((char *) &ke.map[0], 0, 31);
+        rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixReadAccess);
+        if (rc == Success)
+            memcpy((char *) &ke.map[0], (char *) &dev->key->down[1], 31);
 
         ke.type = KeymapNotify;
         DeliverEventsToWindow(dev, pWin, (xEvent *) &ke, 1,
-- 
1.7.9.2



More information about the xorg-devel mailing list