xace: Fake return values on denials in input polling requests.

Instead of returning BadAccess when "read" permission is denied
on a device, falsify the device state (buttons down, keys pressed).
This is nicer to applications, but may still have undesired side
effects.  The long-term solution is not to use these requests in
event-driven code!

Requests affected: QueryPointer, QueryKeymap, XiQueryDevice.

[Backport to 1.6]

Signed-off-by: Eamon Walsh <ewalsh@tycho.nsa.gov>
Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Eamon Walsh 2009-09-15 19:29:34 -04:00 committed by Keith Packard
parent 439c588493
commit c1c7feec90
3 changed files with 23 additions and 7 deletions

View file

@ -96,7 +96,7 @@ ProcXQueryDeviceState(ClientPtr client)
rep.sequenceNumber = client->sequence;
rc = dixLookupDevice(&dev, stuff->deviceid, client, DixReadAccess);
if (rc != Success)
if (rc != Success && rc != BadAccess)
return rc;
v = dev->valuator;
@ -129,8 +129,9 @@ ProcXQueryDeviceState(ClientPtr client)
tk->class = KeyClass;
tk->length = sizeof(xKeyState);
tk->num_keys = k->curKeySyms.maxKeyCode - k->curKeySyms.minKeyCode + 1;
for (i = 0; i < 32; i++)
tk->keys[i] = k->down[i];
if (rc != BadAccess)
for (i = 0; i < 32; i++)
tk->keys[i] = k->down[i];
buf += sizeof(xKeyState);
}
@ -139,7 +140,8 @@ ProcXQueryDeviceState(ClientPtr client)
tb->class = ButtonClass;
tb->length = sizeof(xButtonState);
tb->num_buttons = b->numButtons;
memcpy(tb->buttons, b->down, sizeof(b->down));
if (rc != BadAccess)
memcpy(tb->buttons, b->down, sizeof(b->down));
buf += sizeof(xButtonState);
}
@ -151,7 +153,9 @@ ProcXQueryDeviceState(ClientPtr client)
tv->mode = v->mode;
buf += sizeof(xValuatorState);
for (i = 0, values = v->axisVal; i < v->numAxes; i++) {
*((int *)buf) = *values++;
if (rc != BadAccess)
*((int *)buf) = *values;
values++;
if (client->swapped) {
swapl((int *)buf, n); /* macro - braces needed */
}

View file

@ -2477,12 +2477,15 @@ ProcQueryKeymap(ClientPtr client)
rep.length = 2;
rc = XaceHook(XACE_DEVICE_ACCESS, client, keybd, DixReadAccess);
if (rc != Success)
if (rc != Success && 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;

View file

@ -4771,7 +4771,7 @@ ProcQueryPointer(ClientPtr client)
if (rc != Success)
return rc;
rc = XaceHook(XACE_DEVICE_ACCESS, client, mouse, DixReadAccess);
if (rc != Success)
if (rc != Success && rc != BadAccess)
return rc;
pSprite = mouse->spriteInfo->sprite;
@ -4815,6 +4815,15 @@ ProcQueryPointer(ClientPtr client)
}
#endif
if (rc == BadAccess) {
rep.mask = 0;
rep.child = None;
rep.rootX = 0;
rep.rootY = 0;
rep.winX = 0;
rep.winY = 0;
}
WriteReplyToClient(client, sizeof(xQueryPointerReply), &rep);
return(Success);