Skip to content

Commit

Permalink
Add agressive event type checking.
Browse files Browse the repository at this point in the history
Best to FatalError if a wrong event comes in. At least that forces me to fix
it really quickly.

Signed-off-by: Peter Hutterer <[email protected]>
  • Loading branch information
whot committed Mar 20, 2009
1 parent 836864b commit 6fe4c28
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Xi/exevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,8 @@ ProcessOtherEvent(InternalEvent *ev, DeviceIntPtr device)
DeviceIntPtr mouse = NULL, kbd = NULL;
DeviceEvent *event = (DeviceEvent*)ev;

CHECKEVENT(ev);

if (IsPointerDevice(device))
{
kbd = GetPairedDevice(device);
Expand Down
4 changes: 4 additions & 0 deletions dix/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -2247,6 +2247,8 @@ DeliverDeviceEvents(WindowPtr pWin, InternalEvent *event, GrabPtr grab,
xEvent *xE = NULL;
int rc, count = 0;

CHECKEVENT(event);

/* XXX: In theory, we could pass the internal events through to everything
* and only convert just before hitting the wire. We can't do that yet, so
* DDE is the last stop for internal events. From here onwards, we deal
Expand Down Expand Up @@ -2527,6 +2529,8 @@ CheckMotion(DeviceEvent *ev, DeviceIntPtr pDev)
WindowPtr prevSpriteWin;
SpritePtr pSprite = pDev->spriteInfo->sprite;

CHECKEVENT(ev);

prevSpriteWin = pSprite->win;

if (ev && !syncEvents.playingEvents)
Expand Down
4 changes: 4 additions & 0 deletions include/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ enum {
ET_Internal = 0xFF /* First byte */
} EventType;

#define CHECKEVENT(ev) if (ev && ((InternalEvent*)(ev))->u.any.header != 0xFF) \
FatalError("Wrong event type %d.\n", \
((InternalEvent*)(ev))->u.any.header);

/**
* Used for ALL input device events internal in the server until
* copied into the matching protocol event.
Expand Down
8 changes: 8 additions & 0 deletions mi/mieq.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ mieqEnqueue(DeviceIntPtr pDev, InternalEvent *e)
pthread_mutex_lock(&miEventQueueMutex);
#endif

CHECKEVENT(e);

/* avoid merging events from different devices */
if (e->u.any.type == ET_Motion)
isMotion = pDev->id;
Expand Down Expand Up @@ -285,6 +287,8 @@ static void
FixUpEventForMaster(DeviceIntPtr mdev, DeviceIntPtr sdev,
InternalEvent* original, InternalEvent *master)
{
CHECKEVENT(original);
CHECKEVENT(master);
/* Ensure chained button mappings, i.e. that the detail field is the
* value of the mapped button on the SD, not the physical button */
if (original->u.any.type == ET_ButtonPress ||
Expand Down Expand Up @@ -312,6 +316,8 @@ CopyGetMasterEvent(DeviceIntPtr mdev, DeviceIntPtr sdev,
int len = original->u.any.length;
InternalEvent *mevent;

CHECKEVENT(original);

if (master->evlen < len)
SetMinimumEventSize(master, 1, len);

Expand All @@ -337,6 +343,8 @@ mieqProcessDeviceEvent(DeviceIntPtr dev,
int x = 0, y = 0;
DeviceIntPtr master;

CHECKEVENT(event);

/* Custom event handler */
handler = miEventQueue.handlers[event->u.any.type];

Expand Down

0 comments on commit 6fe4c28

Please sign in to comment.