From 9ea88717db376b54b2c821ab67e846918acc616a Mon Sep 17 00:00:00 2001 From: Jamey Sharp Date: Sun, 3 Jul 2016 22:06:43 +0200 Subject: Make WriteEventsToClient/WriteToClient no-op on fake or dead clients. This matches the test in TryClientEvents, and is a superset of tests done by the callers of these functions. The consequence of forgetting these tests is a server crash, so they're always desirable. In my opinion, it's better to not require the callers to remember to do these checks. For callers that don't do very much work before calling WriteToClient or WriteEventsToClient, I've removed the redundant checks. Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=27497 Signed-off-by: Jamey Sharp Cc: Chris Wilson Reviewed-by: Julien Cristau Reviewed-by: Adam Jackson Backport to nx-libs: Mike Gabriel --- nx-X11/programs/Xserver/Xext/saver.c | 2 -- nx-X11/programs/Xserver/Xext/security.c | 14 +++++--------- nx-X11/programs/Xserver/Xext/shape.c | 2 -- nx-X11/programs/Xserver/Xext/sync.c | 9 +++------ nx-X11/programs/Xserver/damageext/damageext.c | 6 ++---- nx-X11/programs/Xserver/dix/events.c | 3 +++ nx-X11/programs/Xserver/os/io.c | 8 +++++--- nx-X11/programs/Xserver/xfixes/cursor.c | 3 +-- nx-X11/programs/Xserver/xfixes/select.c | 3 +-- 9 files changed, 20 insertions(+), 30 deletions(-) (limited to 'nx-X11/programs') diff --git a/nx-X11/programs/Xserver/Xext/saver.c b/nx-X11/programs/Xserver/Xext/saver.c index 10bb2dc2f..0c5d28eb2 100644 --- a/nx-X11/programs/Xserver/Xext/saver.c +++ b/nx-X11/programs/Xserver/Xext/saver.c @@ -467,8 +467,6 @@ SendScreenSaverNotify (pScreen, state, forced) for (pEv = pPriv->events; pEv; pEv = pEv->next) { client = pEv->client; - if (client->clientGone) - continue; if (!(pEv->mask & mask)) continue; ev.type = ScreenSaverNotify + ScreenSaverEventBase; diff --git a/nx-X11/programs/Xserver/Xext/security.c b/nx-X11/programs/Xserver/Xext/security.c index fe741128e..4f055ffe0 100644 --- a/nx-X11/programs/Xserver/Xext/security.c +++ b/nx-X11/programs/Xserver/Xext/security.c @@ -310,15 +310,11 @@ SecurityDeleteAuthorization( { /* send revocation event event */ ClientPtr client = rClient(pEventClient); - - if (!client->clientGone) - { - xSecurityAuthorizationRevokedEvent are; - are.type = SecurityEventBase + XSecurityAuthorizationRevoked; - are.sequenceNumber = client->sequence; - are.authId = pAuth->id; - WriteEventsToClient(client, 1, (xEvent *)&are); - } + xSecurityAuthorizationRevokedEvent are; + are.type = SecurityEventBase + XSecurityAuthorizationRevoked; + are.sequenceNumber = client->sequence; + are.authId = pAuth->id; + WriteEventsToClient(client, 1, (xEvent *)&are); FreeResource(pEventClient->resource, RT_NONE); } diff --git a/nx-X11/programs/Xserver/Xext/shape.c b/nx-X11/programs/Xserver/Xext/shape.c index 76d1fdd77..80ef71f67 100644 --- a/nx-X11/programs/Xserver/Xext/shape.c +++ b/nx-X11/programs/Xserver/Xext/shape.c @@ -969,8 +969,6 @@ SendShapeNotify (pWin, which) } for (pShapeEvent = *pHead; pShapeEvent; pShapeEvent = pShapeEvent->next) { client = pShapeEvent->client; - if (client == serverClient || client->clientGone) - continue; se.type = ShapeNotify + ShapeEventBase; se.kind = which; se.window = pWin->drawable.id; diff --git a/nx-X11/programs/Xserver/Xext/sync.c b/nx-X11/programs/Xserver/Xext/sync.c index 222ef0353..3eb45a246 100644 --- a/nx-X11/programs/Xserver/Xext/sync.c +++ b/nx-X11/programs/Xserver/Xext/sync.c @@ -563,17 +563,14 @@ SyncSendAlarmNotifyEvents(pAlarm) ane.state = pAlarm->state; /* send to owner */ - if (pAlarm->events && !pAlarm->client->clientGone) + if (pAlarm->events) WriteEventsToClient(pAlarm->client, 1, (xEvent *) &ane); /* send to other interested clients */ for (pcl = pAlarm->pEventClients; pcl; pcl = pcl->next) { - if (!pAlarm->client->clientGone) - { - ane.sequenceNumber = pcl->client->sequence; - WriteEventsToClient(pcl->client, 1, (xEvent *) &ane); - } + ane.sequenceNumber = pcl->client->sequence; + WriteEventsToClient(pcl->client, 1, (xEvent *) &ane); } } diff --git a/nx-X11/programs/Xserver/damageext/damageext.c b/nx-X11/programs/Xserver/damageext/damageext.c index b2ee82657..9ab5b6ad6 100755 --- a/nx-X11/programs/Xserver/damageext/damageext.c +++ b/nx-X11/programs/Xserver/damageext/damageext.c @@ -69,8 +69,7 @@ DamageExtNotify (DamageExtPtr pDamageExt, BoxPtr pBoxes, int nBoxes) ev.area.y = pBoxes[i].y1; ev.area.width = pBoxes[i].x2 - pBoxes[i].x1; ev.area.height = pBoxes[i].y2 - pBoxes[i].y1; - if (!pClient->clientGone) - WriteEventsToClient (pClient, 1, (xEvent *) &ev); + WriteEventsToClient (pClient, 1, (xEvent *) &ev); } } else @@ -79,8 +78,7 @@ DamageExtNotify (DamageExtPtr pDamageExt, BoxPtr pBoxes, int nBoxes) ev.area.y = 0; ev.area.width = pDrawable->width; ev.area.height = pDrawable->height; - if (!pClient->clientGone) - WriteEventsToClient (pClient, 1, (xEvent *) &ev); + WriteEventsToClient (pClient, 1, (xEvent *) &ev); } /* Composite extension marks clients with manual Subwindows as critical */ if (pDamageClient->critical > 0) diff --git a/nx-X11/programs/Xserver/dix/events.c b/nx-X11/programs/Xserver/dix/events.c index 676640f01..4d1472cc8 100644 --- a/nx-X11/programs/Xserver/dix/events.c +++ b/nx-X11/programs/Xserver/dix/events.c @@ -4439,6 +4439,9 @@ WriteEventsToClient(ClientPtr pClient, int count, xEvent *events) xEvent eventTo, *eventFrom; int i; + if (!pClient || pClient == serverClient || pClient->clientGone) + return; + #ifdef XKB if ((!noXkbExtension)&&(!XkbFilterEvents(pClient, count, events))) return; diff --git a/nx-X11/programs/Xserver/os/io.c b/nx-X11/programs/Xserver/os/io.c index 234ce8b58..4d12c6e89 100644 --- a/nx-X11/programs/Xserver/os/io.c +++ b/nx-X11/programs/Xserver/os/io.c @@ -859,14 +859,16 @@ SetCriticalOutputPending(void) int WriteToClient (ClientPtr who, int count, char *buf) { - OsCommPtr oc = (OsCommPtr)who->osPrivate; - ConnectionOutputPtr oco = oc->output; + OsCommPtr oc; + ConnectionOutputPtr oco; int padBytes; #ifdef DEBUG_COMMUNICATION Bool multicount = FALSE; #endif - if (!count) + if (!count || !who || who == serverClient || who->clientGone) return(0); + oc = who->osPrivate; + oco = oc->output; #ifdef DEBUG_COMMUNICATION { char info[128]; diff --git a/nx-X11/programs/Xserver/xfixes/cursor.c b/nx-X11/programs/Xserver/xfixes/cursor.c index 29c6061d6..747471e18 100755 --- a/nx-X11/programs/Xserver/xfixes/cursor.c +++ b/nx-X11/programs/Xserver/xfixes/cursor.c @@ -96,8 +96,7 @@ CursorDisplayCursor (ScreenPtr pScreen, CursorCurrent = pCursor; for (e = cursorEvents; e; e = e->next) { - if ((e->eventMask & XFixesDisplayCursorNotifyMask) && - !e->pClient->clientGone) + if ((e->eventMask & XFixesDisplayCursorNotifyMask)) { xXFixesCursorNotifyEvent ev; ev.type = XFixesEventBase + XFixesCursorNotify; diff --git a/nx-X11/programs/Xserver/xfixes/select.c b/nx-X11/programs/Xserver/xfixes/select.c index 2a20bfe87..540499518 100755 --- a/nx-X11/programs/Xserver/xfixes/select.c +++ b/nx-X11/programs/Xserver/xfixes/select.c @@ -79,8 +79,7 @@ XFixesSelectionCallback (CallbackListPtr *callbacks, void * data, void * args) for (e = selectionEvents; e; e = e->next) { if (e->selection == selection->selection && - (e->eventMask & eventMask) && - !e->pClient->clientGone) + (e->eventMask & eventMask)) { xXFixesSelectionNotifyEvent ev; -- cgit v1.2.3 From cb0089bad114e79d5c6e4577da59fa8911d0ee8d Mon Sep 17 00:00:00 2001 From: Jamey Sharp Date: Sun, 3 Jul 2016 22:52:13 +0200 Subject: Set event sequence number in WriteEventsToClient instead of at callers. TryClientEvents already did this; this commit just moves the assignment one level down so that no event source has to worry about sequence numbers. ...No event source, that is, except XKB, which inexplicably calls WriteToClient directly for several events. Signed-off-by: Jamey Sharp Reviewed-by: Julien Cristau Reviewed-by: Adam Jackson Backport to nx-libs: Mike Gabriel --- nx-X11/programs/Xserver/Xext/saver.c | 5 +---- nx-X11/programs/Xserver/Xext/security.c | 4 +--- nx-X11/programs/Xserver/Xext/shape.c | 5 +---- nx-X11/programs/Xserver/Xext/shm.c | 1 - nx-X11/programs/Xserver/Xext/sync.c | 5 ----- nx-X11/programs/Xserver/Xext/xvdisp.c | 1 - nx-X11/programs/Xserver/dix/dispatch.c | 1 - nx-X11/programs/Xserver/dix/events.c | 12 ++++-------- nx-X11/programs/Xserver/randr/rrcrtc.c | 3 --- nx-X11/programs/Xserver/randr/rroutput.c | 3 --- nx-X11/programs/Xserver/randr/rrproperty.c | 3 --- nx-X11/programs/Xserver/randr/rrscreen.c | 3 --- nx-X11/programs/Xserver/xfixes/cursor.c | 1 - nx-X11/programs/Xserver/xfixes/select.c | 1 - 14 files changed, 7 insertions(+), 41 deletions(-) (limited to 'nx-X11/programs') diff --git a/nx-X11/programs/Xserver/Xext/saver.c b/nx-X11/programs/Xserver/Xext/saver.c index 0c5d28eb2..ab1096351 100644 --- a/nx-X11/programs/Xserver/Xext/saver.c +++ b/nx-X11/programs/Xserver/Xext/saver.c @@ -447,7 +447,6 @@ SendScreenSaverNotify (pScreen, state, forced) ScreenSaverEventPtr pEv; unsigned long mask; xScreenSaverNotifyEvent ev; - ClientPtr client; int kind; UpdateCurrentTimeIf (); @@ -466,18 +465,16 @@ SendScreenSaverNotify (pScreen, state, forced) kind = ScreenSaverInternal; for (pEv = pPriv->events; pEv; pEv = pEv->next) { - client = pEv->client; if (!(pEv->mask & mask)) continue; ev.type = ScreenSaverNotify + ScreenSaverEventBase; ev.state = state; - ev.sequenceNumber = client->sequence; ev.timestamp = currentTime.milliseconds; ev.root = pScreen->root->drawable.id; ev.window = savedScreenInfo[pScreen->myNum].wid; ev.kind = kind; ev.forced = forced; - WriteEventsToClient (client, 1, (xEvent *) &ev); + WriteEventsToClient (pEv->client, 1, (xEvent *) &ev); } } diff --git a/nx-X11/programs/Xserver/Xext/security.c b/nx-X11/programs/Xserver/Xext/security.c index 4f055ffe0..c7cd3f1fd 100644 --- a/nx-X11/programs/Xserver/Xext/security.c +++ b/nx-X11/programs/Xserver/Xext/security.c @@ -309,12 +309,10 @@ SecurityDeleteAuthorization( while ((pEventClient = pAuth->eventClients)) { /* send revocation event event */ - ClientPtr client = rClient(pEventClient); xSecurityAuthorizationRevokedEvent are; are.type = SecurityEventBase + XSecurityAuthorizationRevoked; - are.sequenceNumber = client->sequence; are.authId = pAuth->id; - WriteEventsToClient(client, 1, (xEvent *)&are); + WriteEventsToClient(rClient(pEventClient), 1, (xEvent *)&are); FreeResource(pEventClient->resource, RT_NONE); } diff --git a/nx-X11/programs/Xserver/Xext/shape.c b/nx-X11/programs/Xserver/Xext/shape.c index 80ef71f67..a4aa5bece 100644 --- a/nx-X11/programs/Xserver/Xext/shape.c +++ b/nx-X11/programs/Xserver/Xext/shape.c @@ -915,7 +915,6 @@ SendShapeNotify (pWin, which) int which; { ShapeEventPtr *pHead, pShapeEvent; - ClientPtr client; xShapeNotifyEvent se; BoxRec extents; RegionPtr region; @@ -968,18 +967,16 @@ SendShapeNotify (pWin, which) return; } for (pShapeEvent = *pHead; pShapeEvent; pShapeEvent = pShapeEvent->next) { - client = pShapeEvent->client; se.type = ShapeNotify + ShapeEventBase; se.kind = which; se.window = pWin->drawable.id; - se.sequenceNumber = client->sequence; se.x = extents.x1; se.y = extents.y1; se.width = extents.x2 - extents.x1; se.height = extents.y2 - extents.y1; se.time = currentTime.milliseconds; se.shaped = shaped; - WriteEventsToClient (client, 1, (xEvent *) &se); + WriteEventsToClient (pShapeEvent->client, 1, (xEvent *) &se); } } diff --git a/nx-X11/programs/Xserver/Xext/shm.c b/nx-X11/programs/Xserver/Xext/shm.c index b6e61de36..2f82ebcf6 100644 --- a/nx-X11/programs/Xserver/Xext/shm.c +++ b/nx-X11/programs/Xserver/Xext/shm.c @@ -928,7 +928,6 @@ ProcShmPutImage(client) ev.type = ShmCompletionCode; ev.drawable = stuff->drawable; - ev.sequenceNumber = client->sequence; ev.minorEvent = X_ShmPutImage; ev.majorEvent = ShmReqCode; ev.shmseg = stuff->shmseg; diff --git a/nx-X11/programs/Xserver/Xext/sync.c b/nx-X11/programs/Xserver/Xext/sync.c index 3eb45a246..a137afedd 100644 --- a/nx-X11/programs/Xserver/Xext/sync.c +++ b/nx-X11/programs/Xserver/Xext/sync.c @@ -545,7 +545,6 @@ SyncSendAlarmNotifyEvents(pAlarm) ane.type = SyncEventBase + XSyncAlarmNotify; ane.kind = XSyncAlarmNotify; - ane.sequenceNumber = pAlarm->client->sequence; ane.alarm = pAlarm->alarm_id; if (pTrigger->pCounter) { @@ -568,10 +567,7 @@ SyncSendAlarmNotifyEvents(pAlarm) /* send to other interested clients */ for (pcl = pAlarm->pEventClients; pcl; pcl = pcl->next) - { - ane.sequenceNumber = pcl->client->sequence; WriteEventsToClient(pcl->client, 1, (xEvent *) &ane); - } } @@ -599,7 +595,6 @@ SyncSendCounterNotifyEvents(client, ppAwait, num_events) SyncTrigger *pTrigger = &(*ppAwait)->trigger; pev->type = SyncEventBase + XSyncCounterNotify; pev->kind = XSyncCounterNotify; - pev->sequenceNumber = client->sequence; pev->counter = pTrigger->pCounter->id; pev->wait_value_lo = XSyncValueLow32(pTrigger->test_value); pev->wait_value_hi = XSyncValueHigh32(pTrigger->test_value); diff --git a/nx-X11/programs/Xserver/Xext/xvdisp.c b/nx-X11/programs/Xserver/Xext/xvdisp.c index 905539c0b..923202701 100644 --- a/nx-X11/programs/Xserver/Xext/xvdisp.c +++ b/nx-X11/programs/Xserver/Xext/xvdisp.c @@ -1205,7 +1205,6 @@ ProcXvShmPutImage(ClientPtr client) ev.type = ShmCompletionCode; ev.drawable = stuff->drawable; - ev.sequenceNumber = client->sequence; ev.minorEvent = xv_ShmPutImage; ev.majorEvent = XvReqCode; ev.shmseg = stuff->shmseg; diff --git a/nx-X11/programs/Xserver/dix/dispatch.c b/nx-X11/programs/Xserver/dix/dispatch.c index f799ce289..826adfb5c 100644 --- a/nx-X11/programs/Xserver/dix/dispatch.c +++ b/nx-X11/programs/Xserver/dix/dispatch.c @@ -3953,7 +3953,6 @@ SendErrorToClient(ClientPtr client, unsigned majorCode, unsigned minorCode, memset(&rep, 0, sizeof(xError)); rep.type = X_Error; - rep.sequenceNumber = client->sequence; rep.errorCode = errorCode; rep.majorCode = majorCode; rep.minorCode = minorCode; diff --git a/nx-X11/programs/Xserver/dix/events.c b/nx-X11/programs/Xserver/dix/events.c index 4d1472cc8..6fefa512a 100644 --- a/nx-X11/programs/Xserver/dix/events.c +++ b/nx-X11/programs/Xserver/dix/events.c @@ -1546,14 +1546,6 @@ TryClientEvents (ClientPtr client, xEvent *pEvents, int count, Mask mask, return 1; } #endif - type &= 0177; - if (type != KeymapNotify) - { - /* all extension events must have a sequence number */ - for (i = 0; i < count; i++) - pEvents[i].u.u.sequenceNumber = client->sequence; - } - if (BitIsOn(criticalEvents, type)) { #ifdef SMART_SCHEDULE @@ -4442,6 +4434,10 @@ WriteEventsToClient(ClientPtr pClient, int count, xEvent *events) if (!pClient || pClient == serverClient || pClient->clientGone) return; + for (i = 0; i < count; i++) + if ((events[i].u.u.type & 0x7f) != KeymapNotify) + events[i].u.u.sequenceNumber = pClient->sequence; + #ifdef XKB if ((!noXkbExtension)&&(!XkbFilterEvents(pClient, count, events))) return; diff --git a/nx-X11/programs/Xserver/randr/rrcrtc.c b/nx-X11/programs/Xserver/randr/rrcrtc.c index 072046e14..f1cc8c5e9 100644 --- a/nx-X11/programs/Xserver/randr/rrcrtc.c +++ b/nx-X11/programs/Xserver/randr/rrcrtc.c @@ -274,9 +274,6 @@ RRDeliverCrtcEvent(ClientPtr client, WindowPtr pWin, RRCrtcPtr crtc) xRRCrtcChangeNotifyEvent ce = { .type = RRNotify + RREventBase, .subCode = RRNotify_CrtcChange, -#ifdef NXAGENT_SERVER - .sequenceNumber = client->sequence, -#endif .timestamp = pScrPriv->lastSetTime.milliseconds, .window = pWin->drawable.id, .crtc = crtc->id, diff --git a/nx-X11/programs/Xserver/randr/rroutput.c b/nx-X11/programs/Xserver/randr/rroutput.c index c245de874..3a276e34a 100644 --- a/nx-X11/programs/Xserver/randr/rroutput.c +++ b/nx-X11/programs/Xserver/randr/rroutput.c @@ -351,9 +351,6 @@ RRDeliverOutputEvent(ClientPtr client, WindowPtr pWin, RROutputPtr output) xRROutputChangeNotifyEvent oe = { .type = RRNotify + RREventBase, .subCode = RRNotify_OutputChange, -#ifdef NXAGENT_SERVER - .sequenceNumber = client->sequence, -#endif .timestamp = pScrPriv->lastSetTime.milliseconds, .configTimestamp = pScrPriv->lastConfigTime.milliseconds, .window = pWin->drawable.id, diff --git a/nx-X11/programs/Xserver/randr/rrproperty.c b/nx-X11/programs/Xserver/randr/rrproperty.c index 334fd4720..b97f85b38 100644 --- a/nx-X11/programs/Xserver/randr/rrproperty.c +++ b/nx-X11/programs/Xserver/randr/rrproperty.c @@ -43,9 +43,6 @@ DeliverPropertyEvent(WindowPtr pWin, void *value) if (!(pRREvent->mask & RROutputPropertyNotifyMask)) continue; -#ifdef NXAGENT_SERVER - event->sequenceNumber = pRREvent->client->sequence; -#endif event->window = pRREvent->window->drawable.id; WriteEventsToClient(pRREvent->client, 1, (xEvent *) event); } diff --git a/nx-X11/programs/Xserver/randr/rrscreen.c b/nx-X11/programs/Xserver/randr/rrscreen.c index 81ae5b741..9a6af7f39 100644 --- a/nx-X11/programs/Xserver/randr/rrscreen.c +++ b/nx-X11/programs/Xserver/randr/rrscreen.c @@ -111,9 +111,6 @@ RRDeliverScreenEvent(ClientPtr client, WindowPtr pWin, ScreenPtr pScreen) xRRScreenChangeNotifyEvent se = { .type = RRScreenChangeNotify + RREventBase, -#ifdef NXAGENT_SERVER - .sequenceNumber = client->sequence, -#endif .rotation = (CARD8) (crtc ? crtc->rotation : RR_Rotate_0), .timestamp = pScrPriv->lastSetTime.milliseconds, .configTimestamp = pScrPriv->lastConfigTime.milliseconds, diff --git a/nx-X11/programs/Xserver/xfixes/cursor.c b/nx-X11/programs/Xserver/xfixes/cursor.c index 747471e18..c053a5aa3 100755 --- a/nx-X11/programs/Xserver/xfixes/cursor.c +++ b/nx-X11/programs/Xserver/xfixes/cursor.c @@ -101,7 +101,6 @@ CursorDisplayCursor (ScreenPtr pScreen, xXFixesCursorNotifyEvent ev; ev.type = XFixesEventBase + XFixesCursorNotify; ev.subtype = XFixesDisplayCursorNotify; - ev.sequenceNumber = e->pClient->sequence; ev.window = e->pWindow->drawable.id; ev.cursorSerial = pCursor->serialNumber; ev.timestamp = currentTime.milliseconds; diff --git a/nx-X11/programs/Xserver/xfixes/select.c b/nx-X11/programs/Xserver/xfixes/select.c index 540499518..600abc660 100755 --- a/nx-X11/programs/Xserver/xfixes/select.c +++ b/nx-X11/programs/Xserver/xfixes/select.c @@ -87,7 +87,6 @@ XFixesSelectionCallback (CallbackListPtr *callbacks, void * data, void * args) ev.type = XFixesEventBase + XFixesSelectionNotify; ev.subtype = subtype; - ev.sequenceNumber = e->pClient->sequence; ev.window = e->pWindow->drawable.id; if (subtype == XFixesSetSelectionOwnerNotify) ev.owner = selection->window; -- cgit v1.2.3