Github user mike-jumper commented on a diff in the pull request:

    https://github.com/apache/guacamole-server/pull/154#discussion_r199621521
  
    --- Diff: src/protocols/rdp/guac_rdpdr/rdpdr_messages.c ---
    @@ -122,20 +124,28 @@ static void 
guac_rdpdr_send_client_capability(guac_rdpdrPlugin* rdpdr) {
     
     static void 
guac_rdpdr_send_client_device_list_announce_request(guac_rdpdrPlugin* rdpdr) {
     
    -    int i;
    -    wStream* output_stream = Stream_New(NULL, 256);
    +    /* Calculate number of bytes needed for the stream */
    +    int streamBytes = 16;
    +    for (int i=0; i < rdpdr->devices_registered; i++)
    +        streamBytes += rdpdr->devices[i].device_announce_len;
    +
    +    /* Allocate the stream */
    +    wStream* output_stream = Stream_New(NULL, streamBytes);
     
         /* Write header */
         Stream_Write_UINT16(output_stream, RDPDR_CTYP_CORE);
         Stream_Write_UINT16(output_stream, PAKID_CORE_DEVICELIST_ANNOUNCE);
     
    -    /* List devices */
    +    /* Get the stream for each of the devices. */
         Stream_Write_UINT32(output_stream, rdpdr->devices_registered);
    -    for (i=0; i<rdpdr->devices_registered; i++) {
    -        guac_rdpdr_device* device = &(rdpdr->devices[i]);
    -        device->announce_handler(device, output_stream, i);
    +    for (int i=0; i<rdpdr->devices_registered; i++) {
    +        
    +        Stream_Copy(output_stream, rdpdr->devices[i].device_announce,
    --- End diff --
    
    I'm not sure `Stream_Copy()` is the right function/macro to use in this 
case. Checking the source for FreeRDP 1.1, I see `Stream_Copy()` defined as:
    
    ```c
    #define Stream_Copy(_dst, _src, _n) do { \
        memcpy(_dst->pointer, _src->pointer, _n); \
        _dst->pointer += _n; \
        _src->pointer += _n; \
        } while (0)
    ```
    
    It thus depends on the current write position within the buffer, and 
updates that write position as a result of the call.
    
    Should we be using `Stream_Write()` and `Stream_Buffer()` instead?


---

Reply via email to