From f8b7465fee28ad0652e2f4cbe7d71f644e474c67 Mon Sep 17 00:00:00 2001 From: Mikhail Titov Date: Mon, 3 Dec 2012 10:37:32 -0600 Subject: [PATCH 1/2] This closes #820 Both audin and rdpsnd have subsystems named alsa & pulse. Wrong entry was picked up from the table. --- channels/client/channels.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/channels/client/channels.c b/channels/client/channels.c index 71b089007..9950efb15 100644 --- a/channels/client/channels.c +++ b/channels/client/channels.c @@ -336,32 +336,30 @@ void* freerdp_channels_load_static_addin_entry(LPCSTR pszName, LPSTR pszSubsyste for (i = 0; CLIENT_STATIC_ADDIN_TABLE[i].name != NULL; i++) { - if (pszSubsystem != NULL) + if (strcmp(CLIENT_STATIC_ADDIN_TABLE[i].name, pszName) == 0) { - subsystems = (STATIC_SUBSYSTEM_ENTRY*) CLIENT_STATIC_ADDIN_TABLE[i].table; - - for (j = 0; subsystems[j].name != NULL; j++) + if (pszSubsystem != NULL) { - if (strcmp(subsystems[j].name, pszSubsystem) == 0) + subsystems = (STATIC_SUBSYSTEM_ENTRY*) CLIENT_STATIC_ADDIN_TABLE[i].table; + + for (j = 0; subsystems[j].name != NULL; j++) { - if (pszType) + if (strcmp(subsystems[j].name, pszSubsystem) == 0) { - if (strcmp(subsystems[j].type, pszType) == 0) + if (pszType) + { + if (strcmp(subsystems[j].type, pszType) == 0) + return (void*) subsystems[j].entry; + } + else + { return (void*) subsystems[j].entry; - } - else - { - return (void*) subsystems[j].entry; + } } } } - } - else - { - if (strcmp(CLIENT_STATIC_ADDIN_TABLE[i].name, pszName) == 0) - { + else return (void*) CLIENT_STATIC_ADDIN_TABLE[i].entry; - } } } @@ -1327,3 +1325,7 @@ void freerdp_channels_close(rdpChannels* channels, freerdp* instance) } } +/* Local variables: */ +/* c-basic-offset: 8 */ +/* c-file-style: "linux" */ +/* End: */ From 47fa5f28c4c4da46be1ff4c6a2718c0e306d5420 Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Fri, 7 Dec 2012 19:18:50 -0800 Subject: [PATCH 2/2] when reading PDU, use header to know size --- libfreerdp/core/transport.c | 85 +++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 28 deletions(-) diff --git a/libfreerdp/core/transport.c b/libfreerdp/core/transport.c index f89a053c5..34f52e232 100644 --- a/libfreerdp/core/transport.c +++ b/libfreerdp/core/transport.c @@ -269,44 +269,73 @@ BOOL transport_accept_nla(rdpTransport* transport) return TRUE; } -int transport_read(rdpTransport* transport, STREAM* s) +static int tr(rdpTransport* transport, UINT8* data, int bytes) { int status = -1; - while (TRUE) - { - if (transport->layer == TRANSPORT_LAYER_TLS) - status = tls_read(transport->TlsIn, stream_get_tail(s), stream_get_left(s)); - else if (transport->layer == TRANSPORT_LAYER_TCP) - status = tcp_read(transport->TcpIn, stream_get_tail(s), stream_get_left(s)); - else if (transport->layer == TRANSPORT_LAYER_TSG) - status = tsg_read(transport->tsg, stream_get_tail(s), stream_get_left(s)); - - if ((status == 0) && (transport->blocking)) - { - freerdp_usleep(transport->usleep_interval); - continue; - } - - break; - } - -#ifdef WITH_DEBUG_TRANSPORT - if (status > 0) - { - printf("Local < Remote\n"); - freerdp_hexdump(s->data, status); - } -#endif - + if (transport->layer == TRANSPORT_LAYER_TLS) + status = tls_read(transport->TlsIn, data, bytes); + else if (transport->layer == TRANSPORT_LAYER_TCP) + status = tcp_read(transport->TcpIn, data, bytes); + else if (transport->layer == TRANSPORT_LAYER_TSG) + status = tsg_read(transport->tsg, data, bytes); return status; } +int transport_read(rdpTransport* transport, STREAM* s) +{ + int status; + int pdu_bytes; + int s_bytes; + int rv; + + rv = 0; + /* first check if we have header */ + s_bytes = stream_get_length(s); + if (s_bytes < 4) + { + status = tr(transport, s->data + s_bytes, 4 - s_bytes); + if (status < 0) + { + return status; + } + rv += status; + if (status + s_bytes < 4) + { + return rv; + } + s_bytes += status; + } + /* if header is present, read in exactly one PDU */ + if (s->data[0] == 0x03) + { + pdu_bytes = (s->data[2] << 8) | s->data[3]; + } + else + { + if (s->data[1] & 0x80) + { + pdu_bytes = ((s->data[1] & 0x7f) << 8) | s->data[2]; + } + else + { + pdu_bytes = s->data[1]; + } + } + status = tr(transport, s->data + s_bytes, pdu_bytes - s_bytes); + if (status < 0) + { + return status; + } + rv += status; + return rv; +} + static int transport_read_nonblocking(rdpTransport* transport) { int status; - stream_check_size(transport->recv_buffer, 4096); + stream_check_size(transport->recv_buffer, 32 * 1024); status = transport_read(transport, transport->recv_buffer); if (status <= 0)