Skip to content

Commit 53e347b

Browse files
keith-packardjeremyhu
authored andcommitted
Save major/minor opcodes in ClientRec for RecordAReply
The record extension needs the major and minor opcodes in the reply hook, but the request buffer may have been freed by the time the hook is invoked. Saving the request major and minor codes as the request is executed avoids fetching from the defunct request buffer. This patch also eliminates the public MinorOpcodeOfRequest function, inlining it into Dispatch. Usages of that function have been replaced with direct access to the new ClientRec field. Signed-off-by: Keith Packard <[email protected]> Reviewed-by: Jamey Sharp <[email protected]> (cherry picked from commit fb22a40) Conflicts: include/extension.h
1 parent b736f8c commit 53e347b

File tree

7 files changed

+20
-36
lines changed

7 files changed

+20
-36
lines changed

Xext/security.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,7 @@ SecurityLabelInitial(void)
148148
static _X_INLINE const char *
149149
SecurityLookupRequestName(ClientPtr client)
150150
{
151-
int major = ((xReq *)client->requestBuffer)->reqType;
152-
int minor = MinorOpcodeOfRequest(client);
153-
return LookupRequestName(major, minor);
151+
return LookupRequestName(client->majorOp, client->minorOp);
154152
}
155153

156154

Xext/xselinux_hooks.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ SELinuxAudit(void *auditdata,
263263
if (client) {
264264
REQUEST(xReq);
265265
if (stuff) {
266-
major = stuff->reqType;
267-
minor = MinorOpcodeOfRequest(client);
266+
major = client->majorOp;
267+
minor = client->minorOp;
268268
}
269269
}
270270
if (audit->id)

dix/dispatch.c

+13-10
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,6 @@ DisableLimitedSchedulingLatency(void)
337337
SmartScheduleLatencyLimited = 0;
338338
}
339339

340-
#define MAJOROP ((xReq *)client->requestBuffer)->reqType
341-
342340
void
343341
Dispatch(void)
344342
{
@@ -419,21 +417,28 @@ Dispatch(void)
419417
}
420418

421419
client->sequence++;
420+
client->majorOp = ((xReq *)client->requestBuffer)->reqType;
421+
client->minorOp = 0;
422+
if (client->majorOp >= EXTENSION_BASE) {
423+
ExtensionEntry *ext = GetExtensionEntry(client->majorOp);
424+
if (ext)
425+
client->minorOp = ext->MinorOpcode(client);
426+
}
422427
#ifdef XSERVER_DTRACE
423-
XSERVER_REQUEST_START(LookupMajorName(MAJOROP), MAJOROP,
428+
XSERVER_REQUEST_START(LookupMajorName(client->majorOp), client->majorOp,
424429
((xReq *)client->requestBuffer)->length,
425430
client->index, client->requestBuffer);
426431
#endif
427432
if (result > (maxBigRequestSize << 2))
428433
result = BadLength;
429434
else {
430-
result = XaceHookDispatch(client, MAJOROP);
435+
result = XaceHookDispatch(client, client->majorOp);
431436
if (result == Success)
432-
result = (* client->requestVector[MAJOROP])(client);
437+
result = (* client->requestVector[client->majorOp])(client);
433438
XaceHookAuditEnd(client, result);
434439
}
435440
#ifdef XSERVER_DTRACE
436-
XSERVER_REQUEST_DONE(LookupMajorName(MAJOROP), MAJOROP,
441+
XSERVER_REQUEST_DONE(LookupMajorName(client->majorOp), client->majorOp,
437442
client->sequence, client->index, result);
438443
#endif
439444

@@ -444,8 +449,8 @@ Dispatch(void)
444449
}
445450
else if (result != Success)
446451
{
447-
SendErrorToClient(client, MAJOROP,
448-
MinorOpcodeOfRequest(client),
452+
SendErrorToClient(client, client->majorOp,
453+
client->minorOp,
449454
client->errorValue, result);
450455
break;
451456
}
@@ -466,8 +471,6 @@ Dispatch(void)
466471
SmartScheduleLatencyLimited = 0;
467472
}
468473

469-
#undef MAJOROP
470-
471474
static int VendorRelease = VENDOR_RELEASE;
472475
static char *VendorString = VENDOR_NAME;
473476

dix/extension.c

-14
Original file line numberDiff line numberDiff line change
@@ -228,20 +228,6 @@ StandardMinorOpcode(ClientPtr client)
228228
return ((xReq *)client->requestBuffer)->data;
229229
}
230230

231-
unsigned short
232-
MinorOpcodeOfRequest(ClientPtr client)
233-
{
234-
unsigned char major;
235-
236-
major = ((xReq *)client->requestBuffer)->reqType;
237-
if (major < EXTENSION_BASE)
238-
return 0;
239-
major -= EXTENSION_BASE;
240-
if (major >= NumExtensions)
241-
return 0;
242-
return (*extensions[major]->MinorOpcode)(client);
243-
}
244-
245231
void
246232
CloseDownExtensions(void)
247233
{

include/dixstruct.h

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ typedef struct _Client {
123123

124124
DeviceIntPtr clientPtr;
125125
ClientIdPtr clientIds;
126+
unsigned short majorOp, minorOp;
126127
} ClientRec;
127128

128129
/*

include/extension.h

-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ _XFUNCPROTOBEGIN
5252

5353
extern _X_EXPORT unsigned short StandardMinorOpcode(ClientPtr /*client*/);
5454

55-
extern _X_EXPORT unsigned short MinorOpcodeOfRequest(ClientPtr /*client*/);
56-
5755
extern _X_EXPORT Bool EnableDisableExtension(char *name, Bool enable);
5856

5957
extern _X_EXPORT void EnableDisableExtensionError(char *name, Bool enable);

record/record.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ RecordARequest(ClientPtr client)
554554
}
555555
else /* extension, check minor opcode */
556556
{
557-
int minorop = MinorOpcodeOfRequest(client);
557+
int minorop = client->minorOp;
558558
int numMinOpInfo;
559559
RecordMinorOpPtr pMinorOpInfo = pRCAP->pRequestMinOpInfo;
560560

@@ -611,19 +611,17 @@ RecordAReply(CallbackListPtr *pcbl, pointer nulldata, pointer calldata)
611611
RecordContextPtr pContext;
612612
RecordClientsAndProtocolPtr pRCAP;
613613
int eci;
614-
int majorop;
615614
ReplyInfoRec *pri = (ReplyInfoRec *)calldata;
616615
ClientPtr client = pri->client;
617-
REQUEST(xReq);
618616

619-
majorop = stuff->reqType;
620617
for (eci = 0; eci < numEnabledContexts; eci++)
621618
{
622619
pContext = ppAllContexts[eci];
623620
pRCAP = RecordFindClientOnContext(pContext, client->clientAsMask,
624621
NULL);
625622
if (pRCAP)
626623
{
624+
int majorop = client->majorOp;
627625
if (pContext->continuedReply)
628626
{
629627
RecordAProtocolElement(pContext, client, XRecordFromServer,
@@ -644,7 +642,7 @@ RecordAReply(CallbackListPtr *pcbl, pointer nulldata, pointer calldata)
644642
}
645643
else /* extension, check minor opcode */
646644
{
647-
int minorop = MinorOpcodeOfRequest(client);
645+
int minorop = client->minorOp;
648646
int numMinOpInfo;
649647
RecordMinorOpPtr pMinorOpInfo = pRCAP->pReplyMinOpInfo;
650648
assert (pMinorOpInfo);

0 commit comments

Comments
 (0)