From d8afffd3a801174a8948e72f55ce0a7bca4510ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Sun, 27 Jan 2013 17:17:04 -0500 Subject: [PATCH] libfreerdp-core: fix server-side color depth negotiation --- libfreerdp/core/capabilities.c | 15 ++++++++++----- libfreerdp/core/gcc.c | 7 +++++-- server/Mac/mf_peer.c | 3 ++- server/Windows/wf_peer.c | 1 + server/X11/xf_peer.c | 1 + 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/libfreerdp/core/capabilities.c b/libfreerdp/core/capabilities.c index 4656357d3..34bc46051 100644 --- a/libfreerdp/core/capabilities.c +++ b/libfreerdp/core/capabilities.c @@ -212,8 +212,9 @@ BOOL rdp_read_bitmap_capability_set(STREAM* s, UINT16 length, rdpSettings* setti UINT16 desktopResizeFlag; UINT16 preferredBitsPerPixel; - if(length < 28) + if (length < 28) return FALSE; + stream_read_UINT16(s, preferredBitsPerPixel); /* preferredBitsPerPixel (2 bytes) */ stream_seek_UINT16(s); /* receive1BitPerPixel (2 bytes) */ stream_seek_UINT16(s); /* receive4BitsPerPixel (2 bytes) */ @@ -228,7 +229,7 @@ BOOL rdp_read_bitmap_capability_set(STREAM* s, UINT16 length, rdpSettings* setti stream_seek_UINT16(s); /* multipleRectangleSupport (2 bytes) */ stream_seek_UINT16(s); /* pad2OctetsB (2 bytes) */ - if (!settings->ServerMode && preferredBitsPerPixel != settings->ColorDepth) + if (!settings->ServerMode && (preferredBitsPerPixel != settings->ColorDepth)) { /* The client must respect the actual color depth used by the server */ settings->ColorDepth = preferredBitsPerPixel; @@ -243,6 +244,7 @@ BOOL rdp_read_bitmap_capability_set(STREAM* s, UINT16 length, rdpSettings* setti settings->DesktopWidth = desktopWidth; settings->DesktopHeight = desktopHeight; } + return TRUE; } @@ -1546,8 +1548,9 @@ BOOL rdp_read_bitmap_codecs_capability_set(STREAM* s, UINT16 length, rdpSettings UINT16 codecPropertiesLength; UINT16 remainingLength; - if(length < 5) + if (length < 5) return FALSE; + stream_read_BYTE(s, bitmapCodecCount); /* bitmapCodecCount (1 byte) */ remainingLength = length - 5; @@ -1560,8 +1563,9 @@ BOOL rdp_read_bitmap_codecs_capability_set(STREAM* s, UINT16 length, rdpSettings while (bitmapCodecCount > 0) { - if(remainingLength < 19) + if (remainingLength < 19) return FALSE; + if (settings->ServerMode && strncmp((char*) stream_get_tail(s), CODEC_GUID_REMOTEFX, 16) == 0) { stream_seek(s, 16); /* codecGUID (16 bytes) */ @@ -1582,7 +1586,8 @@ BOOL rdp_read_bitmap_codecs_capability_set(STREAM* s, UINT16 length, rdpSettings stream_read_UINT16(s, codecPropertiesLength); /* codecPropertiesLength (2 bytes) */ remainingLength -= 19; - if(remainingLength < codecPropertiesLength) + + if (remainingLength < codecPropertiesLength) return FALSE; stream_seek(s, codecPropertiesLength); /* codecProperties */ diff --git a/libfreerdp/core/gcc.c b/libfreerdp/core/gcc.c index 0c2953e10..856721049 100644 --- a/libfreerdp/core/gcc.c +++ b/libfreerdp/core/gcc.c @@ -597,7 +597,10 @@ BOOL gcc_read_client_core_data(STREAM* s, rdpSettings* settings, UINT16 blockLen if (highColorDepth > 0) { - color_depth = highColorDepth; + if (earlyCapabilityFlags & RNS_UD_CS_WANT_32BPP_SESSION) + color_depth = 32; + else + color_depth = highColorDepth; } else if (postBeta2ColorDepth > 0) { @@ -641,7 +644,7 @@ BOOL gcc_read_client_core_data(STREAM* s, rdpSettings* settings, UINT16 blockLen * If we are in server mode, accept client's color depth only if * it is smaller than ours. This is what Windows server does. */ - if (color_depth < settings->ColorDepth || !settings->ServerMode) + if ((color_depth < settings->ColorDepth) || !settings->ServerMode) settings->ColorDepth = color_depth; return TRUE; diff --git a/server/Mac/mf_peer.c b/server/Mac/mf_peer.c index 5a9675ac0..680c00c5e 100644 --- a/server/Mac/mf_peer.c +++ b/server/Mac/mf_peer.c @@ -511,6 +511,7 @@ void* mf_peer_main_loop(void* arg) client->settings->PrivateKeyFile = _strdup("server.key"); client->settings->NlaSecurity = FALSE; client->settings->RemoteFxCodec = TRUE; + client->settings->ColorDepth = 32; client->settings->SuppressOutput = TRUE; client->settings->RefreshRect = FALSE; @@ -605,4 +606,4 @@ void* mf_peer_main_loop(void* arg) freerdp_peer_free(client); return NULL; -} \ No newline at end of file +} diff --git a/server/Windows/wf_peer.c b/server/Windows/wf_peer.c index 8c302c54f..8bca9086d 100644 --- a/server/Windows/wf_peer.c +++ b/server/Windows/wf_peer.c @@ -235,6 +235,7 @@ DWORD WINAPI wf_peer_main_loop(LPVOID lpParam) settings = client->settings; settings->RemoteFxCodec = TRUE; + settings->ColorDepth = 32; settings->NSCodec = FALSE; settings->JpegCodec = FALSE; wf_peer_read_settings(client); diff --git a/server/X11/xf_peer.c b/server/X11/xf_peer.c index 6d8690ca9..72f1a141f 100644 --- a/server/X11/xf_peer.c +++ b/server/X11/xf_peer.c @@ -647,6 +647,7 @@ void* xf_peer_main_loop(void* arg) settings->PrivateKeyFile = freerdp_construct_path(server_file_path, "server.key"); settings->RemoteFxCodec = TRUE; + settings->ColorDepth = 32; client->Capabilities = xf_peer_capabilities; client->PostConnect = xf_peer_post_connect;