channels/cliprdr: fix empty clipboard format lists, server-side locking

This commit is contained in:
Marc-André Moreau 2014-12-20 13:07:30 -05:00
parent 265e8b9e9d
commit 08c8c6f285
3 changed files with 27 additions and 4 deletions

View File

@ -57,7 +57,13 @@ void cliprdr_process_format_list(cliprdrPlugin* cliprdr, wStream* s, UINT32 data
formatList.numFormats = 0; formatList.numFormats = 0;
position = Stream_GetPosition(s); position = Stream_GetPosition(s);
if (!cliprdr->useLongFormatNames) if (!formatList.dataLen)
{
/* empty format list */
formatList.formats = NULL;
formatList.numFormats = 0;
}
else if (!cliprdr->useLongFormatNames)
{ {
formatList.numFormats = (dataLen / 36); formatList.numFormats = (dataLen / 36);

View File

@ -330,7 +330,7 @@ static int cliprdr_server_format_data_response(CliprdrServerContext* context, CL
Stream_Write(s, formatDataResponse->requestedFormatData, formatDataResponse->dataLen); Stream_Write(s, formatDataResponse->requestedFormatData, formatDataResponse->dataLen);
WLog_DBG(TAG, "ClientFormatDataResponse"); WLog_DBG(TAG, "ServerFormatDataResponse");
cliprdr_server_packet_send(cliprdr, s); cliprdr_server_packet_send(cliprdr, s);
return 0; return 0;
@ -505,7 +505,13 @@ static int cliprdr_server_receive_format_list(CliprdrServerContext* context, wSt
formatList.numFormats = 0; formatList.numFormats = 0;
position = Stream_GetPosition(s); position = Stream_GetPosition(s);
if (!cliprdr->useLongFormatNames) if (!header->dataLen)
{
/* empty format list */
formatList.formats = NULL;
formatList.numFormats = 0;
}
else if (!cliprdr->useLongFormatNames)
{ {
formatList.numFormats = (dataLen / 36); formatList.numFormats = (dataLen / 36);
@ -895,6 +901,9 @@ int cliprdr_server_read(CliprdrServerContext* context)
BytesReturned = 0; BytesReturned = 0;
BytesToRead = CLIPRDR_HEADER_LENGTH - Stream_GetPosition(s); BytesToRead = CLIPRDR_HEADER_LENGTH - Stream_GetPosition(s);
if (WaitForSingleObject(cliprdr->ChannelEvent, 0) != WAIT_OBJECT_0)
return 1;
if (!WTSVirtualChannelRead(cliprdr->ChannelHandle, 0, if (!WTSVirtualChannelRead(cliprdr->ChannelHandle, 0,
(PCHAR) Stream_Pointer(s), BytesToRead, &BytesReturned)) (PCHAR) Stream_Pointer(s), BytesToRead, &BytesReturned))
{ {
@ -924,6 +933,9 @@ int cliprdr_server_read(CliprdrServerContext* context)
BytesReturned = 0; BytesReturned = 0;
BytesToRead = (header.dataLen + CLIPRDR_HEADER_LENGTH) - Stream_GetPosition(s); BytesToRead = (header.dataLen + CLIPRDR_HEADER_LENGTH) - Stream_GetPosition(s);
if (WaitForSingleObject(cliprdr->ChannelEvent, 0) != WAIT_OBJECT_0)
return 1;
if (!WTSVirtualChannelRead(cliprdr->ChannelHandle, 0, if (!WTSVirtualChannelRead(cliprdr->ChannelHandle, 0,
(PCHAR) Stream_Pointer(s), BytesToRead, &BytesReturned)) (PCHAR) Stream_Pointer(s), BytesToRead, &BytesReturned))
{ {
@ -944,9 +956,12 @@ int cliprdr_server_read(CliprdrServerContext* context)
cliprdr_server_receive_pdu(context, s, &header); cliprdr_server_receive_pdu(context, s, &header);
Stream_SetPosition(s, 0);
/* check for trailing zero bytes */ /* check for trailing zero bytes */
Stream_SetPosition(s, 0); if (WaitForSingleObject(cliprdr->ChannelEvent, 0) != WAIT_OBJECT_0)
return 1;
BytesReturned = 0; BytesReturned = 0;
BytesToRead = 4; BytesToRead = 4;

View File

@ -157,6 +157,8 @@ BOOL ClipboardEmpty(wClipboard* clipboard)
} }
clipboard->size = 0; clipboard->size = 0;
clipboard->formatId = 0;
clipboard->sequenceNumber++; clipboard->sequenceNumber++;
return TRUE; return TRUE;