From 73c02a76372640bc25b0c9e8c692de18a7b56b84 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marc-Andr=C3=A9=20Moreau?= Date: Mon, 19 Aug 2013 12:21:40 -0400 Subject: [PATCH] channels/cliprdr: fix unicode conversion --- channels/cliprdr/server/cliprdr_main.c | 24 +++++++++++++++++++----- channels/rdpdr/server/rdpdr_main.c | 12 ++++++++++-- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/channels/cliprdr/server/cliprdr_main.c b/channels/cliprdr/server/cliprdr_main.c index 0171209..6744748 100644 --- a/channels/cliprdr/server/cliprdr_main.c +++ b/channels/cliprdr/server/cliprdr_main.c @@ -249,6 +249,8 @@ static int cliprdr_server_receive_long_format_list(CliprdrServerContext* context int length; int position; + printf("%s\n", __FUNCTION__); + position = Stream_GetPosition(s); Stream_SetPosition(s, Stream_Length(s)); end = (WCHAR*) Stream_Pointer(s); @@ -281,17 +283,29 @@ static int cliprdr_server_receive_long_format_list(CliprdrServerContext* context { Stream_Read_UINT32(s, context->priv->ClientFormatNames[i].id); /* formatId (4 bytes) */ - context->priv->ClientFormatNames[i].length = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(s), - -1, &context->priv->ClientFormatNames[i].name, 0, NULL, NULL); + length = cliprdr_wcslen((WCHAR*) Stream_Pointer(s), end); + + context->priv->ClientFormatNames[i].name = NULL; + + if (length) + { + context->priv->ClientFormatNames[i].length = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(s), + -1, &(context->priv->ClientFormatNames[i].name), 0, NULL, NULL) - 1; + } + else + { + context->priv->ClientFormatNames[i].length = 0; + } - Stream_Seek(s, (context->priv->ClientFormatNames[i].length + 1) * 2); + Stream_Seek(s, (length + 1) * 2); /* wszFormatName */ } for (i = 0; i < context->priv->ClientFormatNameCount; i++) { - printf("Format %d: Id: 0x%04X Name: %s\n", i, + printf("Format %d: Id: 0x%04X Name: %s Length: %d\n", i, context->priv->ClientFormatNames[i].id, - context->priv->ClientFormatNames[i].name); + context->priv->ClientFormatNames[i].name, + context->priv->ClientFormatNames[i].length); } return 0; diff --git a/channels/rdpdr/server/rdpdr_main.c b/channels/rdpdr/server/rdpdr_main.c index 77c0cd7..c55b6ec 100644 --- a/channels/rdpdr/server/rdpdr_main.c +++ b/channels/rdpdr/server/rdpdr_main.c @@ -90,6 +90,12 @@ static int rdpdr_server_receive_client_name_request(RdpdrServerContext* context, * not in characters, including the NULL terminator! */ + if (context->priv->ClientComputerName) + { + free(context->priv->ClientComputerName); + context->priv->ClientComputerName = NULL; + } + if (UnicodeFlag) { ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(s), @@ -579,6 +585,8 @@ static void* rdpdr_server_thread(void* arg) while (1) { + BytesReturned = 0; + status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); if (WaitForSingleObject(context->priv->StopEvent, 0) == WAIT_OBJECT_0) @@ -586,8 +594,8 @@ static void* rdpdr_server_thread(void* arg) break; } - if (WTSVirtualChannelRead(context->priv->ChannelHandle, 0, - Stream_Buffer(s), Stream_Capacity(s), &BytesReturned)) + if (WTSVirtualChannelRead(context->priv->ChannelHandle, 0, Stream_Pointer(s), + Stream_Capacity(s) - Stream_GetPosition(s), &BytesReturned)) { if (BytesReturned) Stream_Seek(s, BytesReturned); -- 2.7.4