X.Org bug 4947/Sun bug 6646626: Xv extension not byte-swapping properly

X.Org Bugzilla #4947 <https://bugs.freedesktop.org/show_bug.cgi?id=4947>
Sun bug 6646626 <http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6646626>

Don't use swapped data after swapping it.   When done swapping data,
send the swapped data, not the address of the pointer to it, to the client.
This commit is contained in:
Alan Coopersmith 2008-01-02 19:27:22 -08:00
parent f6666dcc3b
commit dfd682b582

View File

@ -67,7 +67,7 @@ SWriteQueryExtensionReply(
swaps(&rep->version, n); swaps(&rep->version, n);
swaps(&rep->revision, n); swaps(&rep->revision, n);
(void)WriteToClient(client, sz_xvQueryExtensionReply, (char *)&rep); (void)WriteToClient(client, sz_xvQueryExtensionReply, (char *)rep);
return Success; return Success;
} }
@ -83,7 +83,7 @@ SWriteQueryAdaptorsReply(
swapl(&rep->length, n); swapl(&rep->length, n);
swaps(&rep->num_adaptors, n); swaps(&rep->num_adaptors, n);
(void)WriteToClient(client, sz_xvQueryAdaptorsReply, (char *)&rep); (void)WriteToClient(client, sz_xvQueryAdaptorsReply, (char *)rep);
return Success; return Success;
} }
@ -99,7 +99,7 @@ SWriteQueryEncodingsReply(
swapl(&rep->length, n); swapl(&rep->length, n);
swaps(&rep->num_encodings, n); swaps(&rep->num_encodings, n);
(void)WriteToClient(client, sz_xvQueryEncodingsReply, (char *)&rep); (void)WriteToClient(client, sz_xvQueryEncodingsReply, (char *)rep);
return Success; return Success;
} }
@ -204,7 +204,7 @@ SWriteGrabPortReply(
swaps(&rep->sequenceNumber, n); swaps(&rep->sequenceNumber, n);
swapl(&rep->length, n); swapl(&rep->length, n);
(void)WriteToClient(client, sz_xvGrabPortReply, (char *)&rep); (void)WriteToClient(client, sz_xvGrabPortReply, (char *)rep);
return Success; return Success;
} }
@ -220,7 +220,7 @@ SWriteGetPortAttributeReply(
swapl(&rep->length, n); swapl(&rep->length, n);
swapl(&rep->value, n); swapl(&rep->value, n);
(void)WriteToClient(client, sz_xvGetPortAttributeReply, (char *)&rep); (void)WriteToClient(client, sz_xvGetPortAttributeReply, (char *)rep);
return Success; return Success;
} }
@ -237,7 +237,7 @@ SWriteQueryBestSizeReply(
swaps(&rep->actual_width, n); swaps(&rep->actual_width, n);
swaps(&rep->actual_height, n); swaps(&rep->actual_height, n);
(void)WriteToClient(client, sz_xvQueryBestSizeReply, (char *)&rep); (void)WriteToClient(client, sz_xvQueryBestSizeReply, (char *)rep);
return Success; return Success;
} }
@ -254,7 +254,7 @@ SWriteQueryPortAttributesReply(
swapl(&rep->num_attributes, n); swapl(&rep->num_attributes, n);
swapl(&rep->text_size, n); swapl(&rep->text_size, n);
(void)WriteToClient(client, sz_xvQueryPortAttributesReply, (char *)&rep); (void)WriteToClient(client, sz_xvQueryPortAttributesReply, (char *)rep);
return Success; return Success;
} }
@ -273,7 +273,7 @@ SWriteQueryImageAttributesReply(
swaps(&rep->width, n); swaps(&rep->width, n);
swaps(&rep->height, n); swaps(&rep->height, n);
(void)WriteToClient(client, sz_xvQueryImageAttributesReply, (char *)&rep); (void)WriteToClient(client, sz_xvQueryImageAttributesReply, (char *)rep);
return Success; return Success;
} }
@ -289,7 +289,7 @@ SWriteListImageFormatsReply(
swapl(&rep->length, n); swapl(&rep->length, n);
swapl(&rep->num_formats, n); swapl(&rep->num_formats, n);
(void)WriteToClient(client, sz_xvListImageFormatsReply, (char *)&rep); (void)WriteToClient(client, sz_xvListImageFormatsReply, (char *)rep);
return Success; return Success;
} }
@ -378,6 +378,7 @@ ProcXvQueryAdaptors(ClientPtr client)
xvAdaptorInfo ainfo; xvAdaptorInfo ainfo;
xvQueryAdaptorsReply rep; xvQueryAdaptorsReply rep;
int totalSize, na, nf, rc; int totalSize, na, nf, rc;
int nameSize;
XvAdaptorPtr pa; XvAdaptorPtr pa;
XvFormatPtr pf; XvFormatPtr pf;
WindowPtr pWin; WindowPtr pWin;
@ -439,12 +440,12 @@ ProcXvQueryAdaptors(ClientPtr client)
ainfo.base_id = pa->base_id; ainfo.base_id = pa->base_id;
ainfo.num_ports = pa->nPorts; ainfo.num_ports = pa->nPorts;
ainfo.type = pa->type; ainfo.type = pa->type;
ainfo.name_size = strlen(pa->name); ainfo.name_size = nameSize = strlen(pa->name);
ainfo.num_formats = pa->nFormats; ainfo.num_formats = pa->nFormats;
_WriteAdaptorInfo(client, &ainfo); _WriteAdaptorInfo(client, &ainfo);
WriteToClient(client, ainfo.name_size, pa->name); WriteToClient(client, nameSize, pa->name);
nf = pa->nFormats; nf = pa->nFormats;
pf = pa->pFormats; pf = pa->pFormats;
@ -469,6 +470,7 @@ ProcXvQueryEncodings(ClientPtr client)
xvEncodingInfo einfo; xvEncodingInfo einfo;
xvQueryEncodingsReply rep; xvQueryEncodingsReply rep;
int totalSize; int totalSize;
int nameSize;
XvPortPtr pPort; XvPortPtr pPort;
int ne; int ne;
XvEncodingPtr pe; XvEncodingPtr pe;
@ -513,13 +515,13 @@ ProcXvQueryEncodings(ClientPtr client)
while (ne--) while (ne--)
{ {
einfo.encoding = pe->id; einfo.encoding = pe->id;
einfo.name_size = strlen(pe->name); einfo.name_size = nameSize = strlen(pe->name);
einfo.width = pe->width; einfo.width = pe->width;
einfo.height = pe->height; einfo.height = pe->height;
einfo.rate.numerator = pe->rate.numerator; einfo.rate.numerator = pe->rate.numerator;
einfo.rate.denominator = pe->rate.denominator; einfo.rate.denominator = pe->rate.denominator;
_WriteEncodingInfo(client, &einfo); _WriteEncodingInfo(client, &einfo);
WriteToClient(client, einfo.name_size, pe->name); WriteToClient(client, nameSize, pe->name);
pe++; pe++;
} }
@ -984,18 +986,19 @@ ProcXvQueryPortAttributes(ClientPtr client)
rep.text_size = 0; rep.text_size = 0;
for(i = 0, pAtt = pPort->pAdaptor->pAttributes; for(i = 0, pAtt = pPort->pAdaptor->pAttributes;
i < rep.num_attributes; i++, pAtt++) i < pPort->pAdaptor->nAttributes; i++, pAtt++)
{ {
rep.text_size += (strlen(pAtt->name) + 1 + 3) & ~3L; rep.text_size += (strlen(pAtt->name) + 1 + 3) & ~3L;
} }
rep.length = (rep.num_attributes * sz_xvAttributeInfo) + rep.text_size; rep.length = (pPort->pAdaptor->nAttributes * sz_xvAttributeInfo)
+ rep.text_size;
rep.length >>= 2; rep.length >>= 2;
_WriteQueryPortAttributesReply(client, &rep); _WriteQueryPortAttributesReply(client, &rep);
for(i = 0, pAtt = pPort->pAdaptor->pAttributes; for(i = 0, pAtt = pPort->pAdaptor->pAttributes;
i < rep.num_attributes; i++, pAtt++) i < pPort->pAdaptor->nAttributes; i++, pAtt++)
{ {
size = strlen(pAtt->name) + 1; /* pass the NULL */ size = strlen(pAtt->name) + 1; /* pass the NULL */
Info.flags = pAtt->flags; Info.flags = pAtt->flags;
@ -1211,6 +1214,7 @@ ProcXvQueryImageAttributes(ClientPtr client)
XvPortPtr pPort; XvPortPtr pPort;
int *offsets; int *offsets;
int *pitches; int *pitches;
int planeLength;
REQUEST(xvQueryImageAttributesReq); REQUEST(xvQueryImageAttributesReq);
REQUEST_SIZE_MATCH(xvQueryImageAttributesReq); REQUEST_SIZE_MATCH(xvQueryImageAttributesReq);
@ -1250,7 +1254,7 @@ ProcXvQueryImageAttributes(ClientPtr client)
rep.type = X_Reply; rep.type = X_Reply;
rep.sequenceNumber = client->sequence; rep.sequenceNumber = client->sequence;
rep.length = num_planes << 1; rep.length = planeLength = num_planes << 1;
rep.num_planes = num_planes; rep.num_planes = num_planes;
rep.width = width; rep.width = width;
rep.height = height; rep.height = height;
@ -1258,8 +1262,8 @@ ProcXvQueryImageAttributes(ClientPtr client)
_WriteQueryImageAttributesReply(client, &rep); _WriteQueryImageAttributesReply(client, &rep);
if(client->swapped) if(client->swapped)
SwapLongs((CARD32*)offsets, rep.length); SwapLongs((CARD32*)offsets, planeLength);
WriteToClient(client, rep.length << 2, (char*)offsets); WriteToClient(client, planeLength << 2, (char*)offsets);
xfree(offsets); xfree(offsets);
@ -1287,13 +1291,13 @@ ProcXvListImageFormats(ClientPtr client)
rep.type = X_Reply; rep.type = X_Reply;
rep.sequenceNumber = client->sequence; rep.sequenceNumber = client->sequence;
rep.num_formats = pPort->pAdaptor->nImages; rep.num_formats = pPort->pAdaptor->nImages;
rep.length = rep.num_formats * sz_xvImageFormatInfo >> 2; rep.length = pPort->pAdaptor->nImages * sz_xvImageFormatInfo >> 2;
_WriteListImageFormatsReply(client, &rep); _WriteListImageFormatsReply(client, &rep);
pImage = pPort->pAdaptor->pImages; pImage = pPort->pAdaptor->pImages;
for(i = 0; i < rep.num_formats; i++, pImage++) { for(i = 0; i < pPort->pAdaptor->nImages; i++, pImage++) {
info.id = pImage->id; info.id = pImage->id;
info.type = pImage->type; info.type = pImage->type;
info.byte_order = pImage->byte_order; info.byte_order = pImage->byte_order;