Fixed misinterpretation of SendChannelData
authorArmin Novak <armin.novak@thincast.com>
Mon, 9 Mar 2020 09:33:58 +0000 (10:33 +0100)
committerakallabeth <akallabeth@users.noreply.github.com>
Tue, 10 Mar 2020 11:21:14 +0000 (12:21 +0100)
SendChannelData was defined with a return value of type int, but
used as BOOL everywhere. Fix the definition to match use.

include/freerdp/freerdp.h
include/freerdp/peer.h
libfreerdp/core/freerdp.c
libfreerdp/core/peer.c
libfreerdp/core/server.c
server/proxy/pf_client.c
server/proxy/pf_server.c

index fd45403..5e26c26 100644 (file)
@@ -176,8 +176,8 @@ extern "C"
 
        typedef int (*pLogonErrorInfo)(freerdp* instance, UINT32 data, UINT32 type);
 
-       typedef int (*pSendChannelData)(freerdp* instance, UINT16 channelId, const BYTE* data,
-                                       int size);
+       typedef BOOL (*pSendChannelData)(freerdp* instance, UINT16 channelId, const BYTE* data,
+                                        size_t size);
        typedef int (*pReceiveChannelData)(freerdp* instance, UINT16 channelId, BYTE* data, int size,
                                           int flags, int totalSize);
 
index ac6ea8c..a81a3b5 100644 (file)
@@ -51,8 +51,8 @@ typedef BOOL (*psPeerLogon)(freerdp_peer* peer, SEC_WINNT_AUTH_IDENTITY* identit
 typedef BOOL (*psPeerAdjustMonitorsLayout)(freerdp_peer* peer);
 typedef BOOL (*psPeerClientCapabilities)(freerdp_peer* peer);
 
-typedef int (*psPeerSendChannelData)(freerdp_peer* peer, UINT16 channelId, const BYTE* data,
-                                     int size);
+typedef BOOL (*psPeerSendChannelData)(freerdp_peer* peer, UINT16 channelId, const BYTE* data,
+                                      size_t size);
 typedef int (*psPeerReceiveChannelData)(freerdp_peer* peer, UINT16 channelId, const BYTE* data,
                                         size_t size, UINT32 flags, size_t totalSize);
 
index d4eb214..6eddefe 100644 (file)
@@ -488,18 +488,10 @@ int freerdp_message_queue_process_pending_messages(freerdp* instance, DWORD id)
        return status;
 }
 
-static int freerdp_send_channel_data(freerdp* instance, UINT16 channelId, const BYTE* data,
-                                     int size)
+static BOOL freerdp_send_channel_data(freerdp* instance, UINT16 channelId, const BYTE* data,
+                                      size_t size)
 {
-       if (size < 0)
-       {
-               WLog_ERR(TAG, "%s: size has invalid value %d", __FUNCTION__, size);
-               return -1;
-       }
-
-       if (!rdp_send_channel_data(instance->context->rdp, channelId, data, (size_t)size))
-               return -2;
-       return 0;
+       return rdp_send_channel_data(instance->context->rdp, channelId, data, size);
 }
 
 BOOL freerdp_disconnect(freerdp* instance)
@@ -1008,7 +1000,7 @@ const char* freerdp_get_logon_error_info_data(UINT32 data)
 /** Allocator function for the rdp_freerdp structure.
  *  @return an allocated structure filled with 0s. Need to be deallocated using freerdp_free()
  */
-freerdp* freerdp_new()
+freerdp* freerdp_new(void)
 {
        freerdp* instance;
        instance = (freerdp*)calloc(1, sizeof(freerdp));
index f160c3c..73fa418 100644 (file)
@@ -736,17 +736,10 @@ static void freerdp_peer_disconnect(freerdp_peer* client)
        transport_disconnect(transport);
 }
 
-static int freerdp_peer_send_channel_data(freerdp_peer* client, UINT16 channelId, const BYTE* data,
-                                          int size)
+static BOOL freerdp_peer_send_channel_data(freerdp_peer* client, UINT16 channelId, const BYTE* data,
+                                           size_t size)
 {
-       if (size < 0)
-       {
-               WLog_ERR(TAG, "%s: invalid size %d", __FUNCTION__, size);
-               return -1;
-       }
-       if (!rdp_send_channel_data(client->context->rdp, channelId, data, (size_t)size))
-               return -1;
-       return 0;
+       return rdp_send_channel_data(client->context->rdp, channelId, data, size);
 }
 
 static BOOL freerdp_peer_is_write_blocked(freerdp_peer* peer)
index 46573fc..6644672 100644 (file)
@@ -478,7 +478,6 @@ BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer)
 
        while (MessageQueue_Peek(vcm->queue, &message, TRUE))
        {
-               int rc;
                BYTE* buffer;
                UINT32 length;
                UINT16 channelId;
@@ -486,8 +485,7 @@ BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer)
                buffer = (BYTE*)message.wParam;
                length = (UINT32)(UINT_PTR)message.lParam;
 
-               rc = vcm->client->SendChannelData(vcm->client, channelId, buffer, length);
-               if (rc < 0)
+               if (!vcm->client->SendChannelData(vcm->client, channelId, buffer, length))
                {
                        status = FALSE;
                }
index 6e8fb5f..b8d0e25 100644 (file)
@@ -197,8 +197,8 @@ static BOOL pf_client_pre_connect(freerdp* instance)
        return TRUE;
 }
 
-static BOOL pf_client_receive_channel_data_hook(freerdp* instance, UINT16 channelId, BYTE* data,
-                                                int size, int flags, int totalSize)
+static int pf_client_receive_channel_data_hook(freerdp* instance, UINT16 channelId, BYTE* data,
+                                               int size, int flags, int totalSize)
 {
        pClientContext* pc = (pClientContext*)instance->context;
        pServerContext* ps = pc->pdata->ps;
@@ -221,11 +221,13 @@ static BOOL pf_client_receive_channel_data_hook(freerdp* instance, UINT16 channe
                        ev.data_len = size;
 
                        if (!pf_modules_run_filter(FILTER_TYPE_CLIENT_PASSTHROUGH_CHANNEL_DATA, pdata, &ev))
-                               return FALSE;
+                               return -1;
 
                        server_channel_id = (UINT64)HashTable_GetItemValue(ps->vc_ids, (void*)channel_name);
-                       return ps->context.peer->SendChannelData(ps->context.peer, (UINT16)server_channel_id,
-                                                                data, size);
+                       if (!ps->context.peer->SendChannelData(ps->context.peer, (UINT16)server_channel_id,
+                                                              data, size))
+                               return -1;
+                       return 0;
                }
        }
 
index b044971..cc32a35 100644 (file)
@@ -226,8 +226,10 @@ static int pf_server_receive_channel_data_hook(freerdp_peer* peer, UINT16 channe
 
                        client_channel_id = (UINT64)HashTable_GetItemValue(pc->vc_ids, (void*)channel_name);
 
-                       return pc->context.instance->SendChannelData(
-                           pc->context.instance, (UINT16)client_channel_id, (BYTE*)data, size);
+                       if (!pc->context.instance->SendChannelData(
+                               pc->context.instance, (UINT16)client_channel_id, (BYTE*)data, size))
+                               return -1;
+                       return 0;
                }
        }