Skip to content

Commit

Permalink
Save major/minor opcodes in ClientRec for RecordAReply
Browse files Browse the repository at this point in the history
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 <keithp@keithp.com>
Reviewed-by: Jamey Sharp <jamey@minilop.net>
(cherry picked from commit fb22a40)

Conflicts:

	include/extension.h
  • Loading branch information
keith-packard authored and jeremyhu committed Dec 21, 2011
1 parent b736f8c commit 53e347b
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 36 deletions.
4 changes: 1 addition & 3 deletions Xext/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ SecurityLabelInitial(void)
static _X_INLINE const char *
SecurityLookupRequestName(ClientPtr client)
{
int major = ((xReq *)client->requestBuffer)->reqType;
int minor = MinorOpcodeOfRequest(client);
return LookupRequestName(major, minor);
return LookupRequestName(client->majorOp, client->minorOp);
}


Expand Down
4 changes: 2 additions & 2 deletions Xext/xselinux_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ SELinuxAudit(void *auditdata,
if (client) {
REQUEST(xReq);
if (stuff) {
major = stuff->reqType;
minor = MinorOpcodeOfRequest(client);
major = client->majorOp;
minor = client->minorOp;
}
}
if (audit->id)
Expand Down
23 changes: 13 additions & 10 deletions dix/dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,6 @@ DisableLimitedSchedulingLatency(void)
SmartScheduleLatencyLimited = 0;
}

#define MAJOROP ((xReq *)client->requestBuffer)->reqType

void
Dispatch(void)
{
Expand Down Expand Up @@ -419,21 +417,28 @@ Dispatch(void)
}

client->sequence++;
client->majorOp = ((xReq *)client->requestBuffer)->reqType;
client->minorOp = 0;
if (client->majorOp >= EXTENSION_BASE) {
ExtensionEntry *ext = GetExtensionEntry(client->majorOp);
if (ext)
client->minorOp = ext->MinorOpcode(client);
}
#ifdef XSERVER_DTRACE
XSERVER_REQUEST_START(LookupMajorName(MAJOROP), MAJOROP,
XSERVER_REQUEST_START(LookupMajorName(client->majorOp), client->majorOp,
((xReq *)client->requestBuffer)->length,
client->index, client->requestBuffer);
#endif
if (result > (maxBigRequestSize << 2))
result = BadLength;
else {
result = XaceHookDispatch(client, MAJOROP);
result = XaceHookDispatch(client, client->majorOp);
if (result == Success)
result = (* client->requestVector[MAJOROP])(client);
result = (* client->requestVector[client->majorOp])(client);
XaceHookAuditEnd(client, result);
}
#ifdef XSERVER_DTRACE
XSERVER_REQUEST_DONE(LookupMajorName(MAJOROP), MAJOROP,
XSERVER_REQUEST_DONE(LookupMajorName(client->majorOp), client->majorOp,
client->sequence, client->index, result);
#endif

Expand All @@ -444,8 +449,8 @@ Dispatch(void)
}
else if (result != Success)
{
SendErrorToClient(client, MAJOROP,
MinorOpcodeOfRequest(client),
SendErrorToClient(client, client->majorOp,
client->minorOp,
client->errorValue, result);
break;
}
Expand All @@ -466,8 +471,6 @@ Dispatch(void)
SmartScheduleLatencyLimited = 0;
}

#undef MAJOROP

static int VendorRelease = VENDOR_RELEASE;
static char *VendorString = VENDOR_NAME;

Expand Down
14 changes: 0 additions & 14 deletions dix/extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,6 @@ StandardMinorOpcode(ClientPtr client)
return ((xReq *)client->requestBuffer)->data;
}

unsigned short
MinorOpcodeOfRequest(ClientPtr client)
{
unsigned char major;

major = ((xReq *)client->requestBuffer)->reqType;
if (major < EXTENSION_BASE)
return 0;
major -= EXTENSION_BASE;
if (major >= NumExtensions)
return 0;
return (*extensions[major]->MinorOpcode)(client);
}

void
CloseDownExtensions(void)
{
Expand Down
1 change: 1 addition & 0 deletions include/dixstruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ typedef struct _Client {

DeviceIntPtr clientPtr;
ClientIdPtr clientIds;
unsigned short majorOp, minorOp;
} ClientRec;

/*
Expand Down
2 changes: 0 additions & 2 deletions include/extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ _XFUNCPROTOBEGIN

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

extern _X_EXPORT unsigned short MinorOpcodeOfRequest(ClientPtr /*client*/);

extern _X_EXPORT Bool EnableDisableExtension(char *name, Bool enable);

extern _X_EXPORT void EnableDisableExtensionError(char *name, Bool enable);
Expand Down
8 changes: 3 additions & 5 deletions record/record.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ RecordARequest(ClientPtr client)
}
else /* extension, check minor opcode */
{
int minorop = MinorOpcodeOfRequest(client);
int minorop = client->minorOp;
int numMinOpInfo;
RecordMinorOpPtr pMinorOpInfo = pRCAP->pRequestMinOpInfo;

Expand Down Expand Up @@ -611,19 +611,17 @@ RecordAReply(CallbackListPtr *pcbl, pointer nulldata, pointer calldata)
RecordContextPtr pContext;
RecordClientsAndProtocolPtr pRCAP;
int eci;
int majorop;
ReplyInfoRec *pri = (ReplyInfoRec *)calldata;
ClientPtr client = pri->client;
REQUEST(xReq);

majorop = stuff->reqType;
for (eci = 0; eci < numEnabledContexts; eci++)
{
pContext = ppAllContexts[eci];
pRCAP = RecordFindClientOnContext(pContext, client->clientAsMask,
NULL);
if (pRCAP)
{
int majorop = client->majorOp;
if (pContext->continuedReply)
{
RecordAProtocolElement(pContext, client, XRecordFromServer,
Expand All @@ -644,7 +642,7 @@ RecordAReply(CallbackListPtr *pcbl, pointer nulldata, pointer calldata)
}
else /* extension, check minor opcode */
{
int minorop = MinorOpcodeOfRequest(client);
int minorop = client->minorOp;
int numMinOpInfo;
RecordMinorOpPtr pMinorOpInfo = pRCAP->pReplyMinOpInfo;
assert (pMinorOpInfo);
Expand Down

0 comments on commit 53e347b

Please sign in to comment.