From d9e271822012db95bc2604b59a9f2595efe0a5d7 Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Date: Thu, 20 Oct 2011 22:34:44 -0700 Subject: [PATCH] XQuartz: appledri: Fix byte swapping in replies Even though it's only valid when local, it is possible for a local client and the server to not match endianness, such as when running a ppc application under Rosetta. Signed-off-by: Jeremy Huddleston Reviewed-by: Jamey Sharp (cherry picked from commit 14205ade0c750191bf43fba8bd55c65dba912cf4) Conflicts: hw/xquartz/xpr/appledri.c Signed-off-by: Jeremy Huddleston (cherry picked from commit 0ad049706d2fa8ff2758c42bdd412fb62bb1e86a) --- hw/xquartz/xpr/appledri.c | 45 +++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/hw/xquartz/xpr/appledri.c b/hw/xquartz/xpr/appledri.c index e1b4134e1..1d37de279 100644 --- a/hw/xquartz/xpr/appledri.c +++ b/hw/xquartz/xpr/appledri.c @@ -91,7 +91,6 @@ ProcAppleDRIQueryVersion( ) { xAppleDRIQueryVersionReply rep; - register int n; REQUEST_SIZE_MATCH(xAppleDRIQueryVersionReq); rep.type = X_Reply; @@ -101,8 +100,12 @@ ProcAppleDRIQueryVersion( rep.minorVersion = SERVER_APPLEDRI_MINOR_VERSION; rep.patchVersion = SERVER_APPLEDRI_PATCH_VERSION; if (client->swapped) { + register int n; swaps(&rep.sequenceNumber, n); swapl(&rep.length, n); + swaps(&rep.majorVersion, n); + swaps(&rep.minorVersion, n); + swapl(&rep.patchVersion, n); } WriteToClient(client, sizeof(xAppleDRIQueryVersionReply), (char *)&rep); return Success; @@ -134,6 +137,12 @@ ProcAppleDRIQueryDirectRenderingCapable( if (!LocalClient(client)) rep.isCapable = 0; + if (client->swapped) { + register int n; + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + } + WriteToClient(client, sizeof(xAppleDRIQueryDirectRenderingCapableReply), (char *)&rep); return Success; @@ -158,6 +167,14 @@ ProcAppleDRIAuthConnection( ErrorF("Failed to authenticate %u\n", (unsigned int)stuff->magic); rep.authenticated = 0; } + + if (client->swapped) { + register int n; + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swapl(&rep.authenticated, n); /* Yes, this is a CARD32 ... sigh */ + } + WriteToClient(client, sizeof(xAppleDRIAuthConnectionReply), (char *)&rep); return Success; } @@ -217,6 +234,15 @@ ProcAppleDRICreateSurface( rep.key_1 = key[1]; rep.uid = sid; + if (client->swapped) { + register int n; + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swapl(&rep.key_0, n); + swapl(&rep.key_1, n); + swapl(&rep.uid, n); + } + WriteToClient(client, sizeof(xAppleDRICreateSurfaceReply), (char *)&rep); return Success; } @@ -278,7 +304,6 @@ ProcAppleDRICreatePixmap(ClientPtr client) rep.stringLength = strlen(path) + 1; - /* No need for swapping, because this only runs if LocalClient is true. */ rep.type = X_Reply; rep.length = bytes_to_int32(rep.stringLength); rep.sequenceNumber = client->sequence; @@ -291,8 +316,20 @@ ProcAppleDRICreatePixmap(ClientPtr client) if(sizeof(rep) != sz_xAppleDRICreatePixmapReply) ErrorF("error sizeof(rep) is %zu\n", sizeof(rep)); - WriteReplyToClient(client, sizeof(rep), &rep); - (void)WriteToClient(client, rep.stringLength, path); + if (client->swapped) { + register int n; + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swapl(&rep.stringLength, n); + swapl(&rep.width, n); + swapl(&rep.height, n); + swapl(&rep.pitch, n); + swapl(&rep.bpp, n); + swapl(&rep.size, n); + } + + WriteToClient(client, sizeof(rep), &rep); + WriteToClient(client, rep.stringLength, path); return Success; }