[PATCH v2 05/29] ProcQueryKeymap: rework logic around permission to copy key states

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


Always initialize to zero, and then if permission is granted, copy
the current key state maps, instead of always copying and then
zeroing out if permission was denied.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 dix/devices.c |   16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/dix/devices.c b/dix/devices.c
index ba84608..b2cc594 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -2382,17 +2382,19 @@ ProcQueryKeymap(ClientPtr client)
     rep.type = X_Reply;
     rep.sequenceNumber = client->sequence;
     rep.length = 2;
+    memset(rep.map, 0, 32);
 
     rc = XaceHook(XACE_DEVICE_ACCESS, client, keybd, DixReadAccess);
-    if (rc != Success && rc != BadAccess)
+    /* If rc is Success, we're allowed to copy out the keymap.
+     * If it's BadAccess, we leave it empty & lie to the client.
+     */
+    if (rc == Success) {
+        for (i = 0; i < 32; i++)
+            rep.map[i] = down[i];
+    }
+    else if (rc != BadAccess)
         return rc;
 
-    for (i = 0; i < 32; i++)
-        rep.map[i] = down[i];
-
-    if (rc == BadAccess)
-        memset(rep.map, 0, 32);
-
     WriteReplyToClient(client, sizeof(xQueryKeymapReply), &rep);
 
     return Success;
-- 
1.7.9.2



More information about the xorg-devel mailing list