channels/cliprdr: fix unicode conversion
authorMarc-André Moreau <marcandre.moreau@gmail.com>
Mon, 19 Aug 2013 16:21:40 +0000 (12:21 -0400)
committerMarc-André Moreau <marcandre.moreau@gmail.com>
Mon, 19 Aug 2013 16:21:40 +0000 (12:21 -0400)
channels/cliprdr/server/cliprdr_main.c
channels/rdpdr/server/rdpdr_main.c

index 0171209..6744748 100644 (file)
@@ -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;
index 77c0cd7..c55b6ec 100644 (file)
@@ -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);