2010-07-27 13:02:24 -06:00
|
|
|
/**
|
|
|
|
* Copyright © 2009 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Protocol testing for XISelectEvents request.
|
|
|
|
*
|
|
|
|
* Test approach:
|
|
|
|
*
|
|
|
|
* Wrap XISetEventMask to intercept when the server tries to apply the event
|
|
|
|
* mask. Ensure that the mask passed in is equivalent to the one supplied by
|
|
|
|
* the client. Ensure that invalid devices and invalid masks return errors
|
|
|
|
* as appropriate.
|
|
|
|
*
|
|
|
|
* Tests included:
|
|
|
|
* BadValue for num_masks < 0
|
|
|
|
* BadWindow for invalid windows
|
|
|
|
* BadDevice for non-existing devices
|
|
|
|
* BadImplemenation for devices >= 0xFF
|
|
|
|
* BadValue if HierarchyChanged bit is set for devices other than
|
|
|
|
* XIAllDevices
|
|
|
|
* BadValue for invalid mask bits
|
|
|
|
* Sucecss for excessive mask lengths
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xproto.h>
|
|
|
|
#include <X11/extensions/XI2proto.h>
|
|
|
|
#include "inputstr.h"
|
|
|
|
#include "windowstr.h"
|
2012-06-10 07:21:05 -06:00
|
|
|
#include "extinit.h" /* for XInputExtensionInit */
|
2010-07-27 13:02:24 -06:00
|
|
|
#include "scrnintstr.h"
|
2013-06-07 11:28:45 -06:00
|
|
|
#include "exglobals.h"
|
2010-07-27 13:02:24 -06:00
|
|
|
#include "xiselectev.h"
|
|
|
|
|
|
|
|
#include "protocol-common.h"
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static unsigned char *data[4096 * 20]; /* the request data buffer */
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2019-07-27 01:57:06 -06:00
|
|
|
ClientRec client_window;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
int
|
2019-07-27 01:57:06 -06:00
|
|
|
__real_XISetEventMask(DeviceIntPtr dev, WindowPtr win, ClientPtr client,
|
|
|
|
int len, unsigned char *mask);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
int
|
2019-07-27 01:57:06 -06:00
|
|
|
__wrap_XISetEventMask(DeviceIntPtr dev, WindowPtr win, ClientPtr client,
|
|
|
|
int len, unsigned char *mask)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
2019-07-27 01:57:06 -06:00
|
|
|
if (!enable_XISetEventMask_wrap)
|
|
|
|
return __real_XISetEventMask(dev, win, client, len, mask);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2019-07-27 01:57:06 -06:00
|
|
|
return Success;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
request_XISelectEvent(xXISelectEventsReq * req, int error)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int rc;
|
|
|
|
ClientRec client;
|
|
|
|
xXIEventMask *mask, *next;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
req->length = (sz_xXISelectEventsReq / 4);
|
2013-06-07 11:28:45 -06:00
|
|
|
mask = (xXIEventMask *) &req[1];
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < req->num_masks; i++) {
|
|
|
|
req->length += sizeof(xXIEventMask) / 4 + mask->mask_len;
|
|
|
|
mask = (xXIEventMask *) ((char *) &mask[1] + mask->mask_len * 4);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
client = init_client(req->length, req);
|
|
|
|
|
|
|
|
rc = ProcXISelectEvents(&client);
|
2011-11-05 07:32:40 -06:00
|
|
|
assert(rc == error);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
client.swapped = TRUE;
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
mask = (xXIEventMask *) &req[1];
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < req->num_masks; i++) {
|
|
|
|
next = (xXIEventMask *) ((char *) &mask[1] + mask->mask_len * 4);
|
|
|
|
swaps(&mask->deviceid);
|
|
|
|
swaps(&mask->mask_len);
|
2010-07-27 13:02:24 -06:00
|
|
|
mask = next;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
swapl(&req->win);
|
|
|
|
swaps(&req->length);
|
|
|
|
swaps(&req->num_masks);
|
2010-07-27 13:02:24 -06:00
|
|
|
rc = SProcXISelectEvents(&client);
|
2011-11-05 07:32:40 -06:00
|
|
|
assert(rc == error);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
_set_bit(unsigned char *bits, int bit)
|
|
|
|
{
|
|
|
|
SetBit(bits, bit);
|
|
|
|
if (bit >= XI_TouchBegin && bit <= XI_TouchOwnership) {
|
|
|
|
SetBit(bits, XI_TouchBegin);
|
|
|
|
SetBit(bits, XI_TouchUpdate);
|
|
|
|
SetBit(bits, XI_TouchEnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_clear_bit(unsigned char *bits, int bit)
|
|
|
|
{
|
|
|
|
ClearBit(bits, bit);
|
|
|
|
if (bit >= XI_TouchBegin && bit <= XI_TouchOwnership) {
|
|
|
|
ClearBit(bits, XI_TouchBegin);
|
|
|
|
ClearBit(bits, XI_TouchUpdate);
|
|
|
|
ClearBit(bits, XI_TouchEnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
request_XISelectEvents_masks(xXISelectEventsReq * req)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
xXIEventMask *mask;
|
2012-06-10 07:21:05 -06:00
|
|
|
int nmasks = (XI2LASTEVENT + 7) / 8;
|
2010-07-27 13:02:24 -06:00
|
|
|
unsigned char *bits;
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
mask = (xXIEventMask *) &req[1];
|
2010-07-27 13:02:24 -06:00
|
|
|
req->win = ROOT_WINDOW_ID;
|
|
|
|
|
|
|
|
/* if a clients submits more than 100 masks, consider it insane and untested */
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 1; i <= 1000; i++) {
|
2010-07-27 13:02:24 -06:00
|
|
|
req->num_masks = i;
|
|
|
|
mask->deviceid = XIAllDevices;
|
|
|
|
|
|
|
|
/* Test 0:
|
|
|
|
* mask_len is 0 -> Success
|
|
|
|
*/
|
|
|
|
mask->mask_len = 0;
|
|
|
|
request_XISelectEvent(req, Success);
|
|
|
|
|
|
|
|
/* Test 1:
|
2011-11-05 07:32:40 -06:00
|
|
|
* mask may be larger than needed for XI2LASTEVENT.
|
2010-07-27 13:02:24 -06:00
|
|
|
* Test setting each valid mask bit, while leaving unneeded bits 0.
|
|
|
|
* -> Success
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
bits = (unsigned char *) &mask[1];
|
|
|
|
mask->mask_len = (nmasks + 3) / 4 * 10;
|
2010-07-27 13:02:24 -06:00
|
|
|
memset(bits, 0, mask->mask_len * 4);
|
2012-06-10 07:21:05 -06:00
|
|
|
for (j = 0; j <= XI2LASTEVENT; j++) {
|
|
|
|
_set_bit(bits, j);
|
2010-07-27 13:02:24 -06:00
|
|
|
request_XISelectEvent(req, Success);
|
2012-06-10 07:21:05 -06:00
|
|
|
_clear_bit(bits, j);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Test 2:
|
2011-11-05 07:32:40 -06:00
|
|
|
* mask may be larger than needed for XI2LASTEVENT.
|
2010-07-27 13:02:24 -06:00
|
|
|
* Test setting all valid mask bits, while leaving unneeded bits 0.
|
|
|
|
* -> Success
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
bits = (unsigned char *) &mask[1];
|
|
|
|
mask->mask_len = (nmasks + 3) / 4 * 10;
|
2010-07-27 13:02:24 -06:00
|
|
|
memset(bits, 0, mask->mask_len * 4);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (j = 0; j <= XI2LASTEVENT; j++) {
|
|
|
|
_set_bit(bits, j);
|
2010-07-27 13:02:24 -06:00
|
|
|
request_XISelectEvent(req, Success);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test 3:
|
2011-11-05 07:32:40 -06:00
|
|
|
* mask is larger than needed for XI2LASTEVENT. If any unneeded bit
|
2010-07-27 13:02:24 -06:00
|
|
|
* is set -> BadValue
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
bits = (unsigned char *) &mask[1];
|
|
|
|
mask->mask_len = (nmasks + 3) / 4 * 10;
|
2010-07-27 13:02:24 -06:00
|
|
|
memset(bits, 0, mask->mask_len * 4);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (j = XI2LASTEVENT + 1; j < mask->mask_len * 4; j++) {
|
|
|
|
_set_bit(bits, j);
|
2010-07-27 13:02:24 -06:00
|
|
|
request_XISelectEvent(req, BadValue);
|
2012-06-10 07:21:05 -06:00
|
|
|
_clear_bit(bits, j);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Test 4:
|
|
|
|
* Mask len is a sensible length, only valid bits are set -> Success
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
bits = (unsigned char *) &mask[1];
|
|
|
|
mask->mask_len = (nmasks + 3) / 4;
|
2010-07-27 13:02:24 -06:00
|
|
|
memset(bits, 0, mask->mask_len * 4);
|
2012-06-10 07:21:05 -06:00
|
|
|
for (j = 0; j <= XI2LASTEVENT; j++) {
|
|
|
|
_set_bit(bits, j);
|
2010-07-27 13:02:24 -06:00
|
|
|
request_XISelectEvent(req, Success);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test 5:
|
|
|
|
* HierarchyChanged bit is BadValue for devices other than
|
|
|
|
* XIAllDevices
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
bits = (unsigned char *) &mask[1];
|
|
|
|
mask->mask_len = (nmasks + 3) / 4;
|
2010-07-27 13:02:24 -06:00
|
|
|
memset(bits, 0, mask->mask_len * 4);
|
|
|
|
SetBit(bits, XI_HierarchyChanged);
|
|
|
|
mask->deviceid = XIAllDevices;
|
|
|
|
request_XISelectEvent(req, Success);
|
2012-06-10 07:21:05 -06:00
|
|
|
for (j = 1; j < devices.num_devices; j++) {
|
2010-07-27 13:02:24 -06:00
|
|
|
mask->deviceid = j;
|
|
|
|
request_XISelectEvent(req, BadValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test 6:
|
|
|
|
* All bits set minus hierarchy changed bit -> Success
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
bits = (unsigned char *) &mask[1];
|
|
|
|
mask->mask_len = (nmasks + 3) / 4;
|
2010-07-27 13:02:24 -06:00
|
|
|
memset(bits, 0, mask->mask_len * 4);
|
2011-11-05 07:32:40 -06:00
|
|
|
for (j = 0; j <= XI2LASTEVENT; j++)
|
2012-06-10 07:21:05 -06:00
|
|
|
_set_bit(bits, j);
|
|
|
|
_clear_bit(bits, XI_HierarchyChanged);
|
|
|
|
for (j = 1; j < 6; j++) {
|
2010-07-27 13:02:24 -06:00
|
|
|
mask->deviceid = j;
|
|
|
|
request_XISelectEvent(req, Success);
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
mask =
|
|
|
|
(xXIEventMask *) ((char *) mask + sizeof(xXIEventMask) +
|
|
|
|
mask->mask_len * 4);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
test_XISelectEvents(void)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
xXIEventMask *mask;
|
|
|
|
xXISelectEventsReq *req;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
req = (xXISelectEventsReq *) data;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
request_init(req, XISelectEvents);
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
printf("Testing for BadValue on zero-length masks\n");
|
2010-07-27 13:02:24 -06:00
|
|
|
/* zero masks are BadValue, regardless of the window */
|
|
|
|
req->num_masks = 0;
|
|
|
|
|
|
|
|
req->win = None;
|
|
|
|
request_XISelectEvent(req, BadValue);
|
|
|
|
|
|
|
|
req->win = ROOT_WINDOW_ID;
|
|
|
|
request_XISelectEvent(req, BadValue);
|
|
|
|
|
|
|
|
req->win = CLIENT_WINDOW_ID;
|
|
|
|
request_XISelectEvent(req, BadValue);
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
printf("Testing for BadWindow.\n");
|
2010-07-27 13:02:24 -06:00
|
|
|
/* None window is BadWindow, regardless of the masks.
|
|
|
|
* We don't actually need to set the masks here, BadWindow must occur
|
|
|
|
* before checking the masks.
|
|
|
|
*/
|
|
|
|
req->win = None;
|
|
|
|
req->num_masks = 1;
|
|
|
|
request_XISelectEvent(req, BadWindow);
|
|
|
|
|
|
|
|
req->num_masks = 2;
|
|
|
|
request_XISelectEvent(req, BadWindow);
|
|
|
|
|
|
|
|
req->num_masks = 0xFF;
|
|
|
|
request_XISelectEvent(req, BadWindow);
|
|
|
|
|
|
|
|
/* request size is 3, so 0xFFFC is the highest num_mask that doesn't
|
|
|
|
* overflow req->length */
|
|
|
|
req->num_masks = 0xFFFC;
|
|
|
|
request_XISelectEvent(req, BadWindow);
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
printf("Triggering num_masks/length overflow\n");
|
2010-07-27 13:02:24 -06:00
|
|
|
req->win = ROOT_WINDOW_ID;
|
|
|
|
/* Integer overflow - req->length can't hold that much */
|
|
|
|
req->num_masks = 0xFFFF;
|
|
|
|
request_XISelectEvent(req, BadLength);
|
|
|
|
|
|
|
|
req->win = ROOT_WINDOW_ID;
|
|
|
|
req->num_masks = 1;
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
printf("Triggering bogus mask length error\n");
|
2013-06-07 11:28:45 -06:00
|
|
|
mask = (xXIEventMask *) &req[1];
|
2010-07-27 13:02:24 -06:00
|
|
|
mask->deviceid = 0;
|
|
|
|
mask->mask_len = 0xFFFF;
|
|
|
|
request_XISelectEvent(req, BadLength);
|
|
|
|
|
|
|
|
/* testing various device ids */
|
2011-11-05 07:32:40 -06:00
|
|
|
printf("Testing existing device ids.\n");
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < 6; i++) {
|
2013-06-07 11:28:45 -06:00
|
|
|
mask = (xXIEventMask *) &req[1];
|
2010-07-27 13:02:24 -06:00
|
|
|
mask->deviceid = i;
|
|
|
|
mask->mask_len = 1;
|
|
|
|
req->win = ROOT_WINDOW_ID;
|
|
|
|
req->num_masks = 1;
|
|
|
|
request_XISelectEvent(req, Success);
|
|
|
|
}
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
printf("Testing non-existing device ids.\n");
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 6; i <= 0xFFFF; i++) {
|
2010-07-27 13:02:24 -06:00
|
|
|
req->win = ROOT_WINDOW_ID;
|
|
|
|
req->num_masks = 1;
|
2013-06-07 11:28:45 -06:00
|
|
|
mask = (xXIEventMask *) &req[1];
|
2010-07-27 13:02:24 -06:00
|
|
|
mask->deviceid = i;
|
|
|
|
mask->mask_len = 1;
|
|
|
|
request_XISelectEvent(req, BadDevice);
|
|
|
|
}
|
|
|
|
|
|
|
|
request_XISelectEvents_masks(req);
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
int
|
2019-07-27 01:57:06 -06:00
|
|
|
protocol_xiselectevents_test(void)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
init_simple();
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
test_XISelectEvents();
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
return 0;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|