dix: protect event generation against single-valuator devices.

If we have a single-axis device and it sends events it should not access
non-existant memory.
This commit is contained in:
Peter Hutterer 2009-05-21 14:11:27 +10:00
parent b25e29e801
commit da0d3baf71

View File

@ -576,6 +576,9 @@ clipAxis(DeviceIntPtr pDev, int axisNum, int *val)
AxisInfoPtr axis = pDev->valuator->axes + axisNum; AxisInfoPtr axis = pDev->valuator->axes + axisNum;
/* InitValuatoraAxisStruct ensures that (min < max). */ /* InitValuatoraAxisStruct ensures that (min < max). */
if (axisNum >= pDev->valuator->numAxes)
return;
/* If a value range is defined, clip. If not, do nothing */ /* If a value range is defined, clip. If not, do nothing */
if (axis->max_value <= axis->min_value) if (axis->max_value <= axis->min_value)
return; return;
@ -751,8 +754,16 @@ positionSprite(DeviceIntPtr dev, int *x, int *y,
ScreenPtr scr, int *screenx, int *screeny) ScreenPtr scr, int *screenx, int *screeny)
{ {
/* scale x&y to screen */ /* scale x&y to screen */
*screenx = rescaleValuatorAxis(*x, dev->valuator->axes + 0, NULL, scr->width); if (dev->valuator->numAxes > 0)
*screeny = rescaleValuatorAxis(*y, dev->valuator->axes + 1, NULL, scr->height); *screenx = rescaleValuatorAxis(*x, dev->valuator->axes + 0, NULL, scr->width);
else
*screenx = dev->last.valuators[0];
if (dev->valuator->numAxes > 1 )
*screeny = rescaleValuatorAxis(*y, dev->valuator->axes + 1, NULL, scr->height);
else
*screeny = dev->last.valuators[1];
dev->last.valuators[0] = *screenx; dev->last.valuators[0] = *screenx;
dev->last.valuators[1] = *screeny; dev->last.valuators[1] = *screeny;
@ -1006,7 +1017,7 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons,
CARD32 ms; CARD32 ms;
DeviceEvent *event; DeviceEvent *event;
RawDeviceEvent *raw; RawDeviceEvent *raw;
int x, y, /* switches between device and screen coords */ int x = 0, y = 0, /* switches between device and screen coords */
cx, cy; /* only screen coordinates */ cx, cy; /* only screen coordinates */
ScreenPtr scr = miPointerGetScreen(pDev); ScreenPtr scr = miPointerGetScreen(pDev);
@ -1040,11 +1051,12 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons,
{ {
valuators[0] = rescaleValuatorAxis(valuators[0], NULL, valuators[0] = rescaleValuatorAxis(valuators[0], NULL,
pDev->valuator->axes + 0, pDev->valuator->axes + 0,
scr->width); scr->width);
valuators[1] = rescaleValuatorAxis(valuators[1], NULL, if (num_valuators > 1)
pDev->valuator->axes + 1, valuators[1] = rescaleValuatorAxis(valuators[1], NULL,
scr->height); pDev->valuator->axes + 1,
scr->height);
} }
moveAbsolute(pDev, &x, &y, first_valuator, num_valuators, valuators); moveAbsolute(pDev, &x, &y, first_valuator, num_valuators, valuators);
@ -1055,7 +1067,7 @@ GetPointerEvents(EventList *events, DeviceIntPtr pDev, int type, int buttons,
} }
set_raw_valuators(raw, first_valuator, num_valuators, valuators, set_raw_valuators(raw, first_valuator, num_valuators, valuators,
raw->valuators.data); raw->valuators.data);
positionSprite(pDev, &x, &y, scr, &cx, &cy); positionSprite(pDev, &x, &y, scr, &cx, &cy);
updateHistory(pDev, first_valuator, num_valuators, ms); updateHistory(pDev, first_valuator, num_valuators, ms);