@@ -371,7 +371,9 @@ static UINT guac_rdp_cliprdr_format_data_request(CliprdrClientContext* cliprdr,
371
371
372
372
guac_iconv_write * remote_writer ;
373
373
const char * input = clipboard -> clipboard -> buffer ;
374
- char * output = guac_mem_alloc (GUAC_COMMON_CLIPBOARD_MAX_LENGTH );
374
+
375
+ int output_buf_size = clipboard -> clipboard -> available ;
376
+ char * output = guac_mem_alloc (output_buf_size );
375
377
376
378
/* Map requested clipboard format to a guac_iconv writer */
377
379
switch (format_data_request -> requestedFormatId ) {
@@ -402,7 +404,7 @@ static UINT guac_rdp_cliprdr_format_data_request(CliprdrClientContext* cliprdr,
402
404
BYTE * start = (BYTE * ) output ;
403
405
guac_iconv_read * local_reader = settings -> normalize_clipboard ? GUAC_READ_UTF8_NORMALIZED : GUAC_READ_UTF8 ;
404
406
guac_iconv (local_reader , & input , clipboard -> clipboard -> length ,
405
- remote_writer , & output , GUAC_COMMON_CLIPBOARD_MAX_LENGTH );
407
+ remote_writer , & output , output_buf_size );
406
408
407
409
CLIPRDR_FORMAT_DATA_RESPONSE data_response = {
408
410
.requestedFormatData = (BYTE * ) start ,
@@ -470,7 +472,8 @@ static UINT guac_rdp_cliprdr_format_data_response(CliprdrClientContext* cliprdr,
470
472
return CHANNEL_RC_OK ;
471
473
}
472
474
473
- char received_data [GUAC_COMMON_CLIPBOARD_MAX_LENGTH ];
475
+ int output_buf_size = clipboard -> clipboard -> available ;
476
+ char * received_data = guac_mem_alloc (output_buf_size );
474
477
475
478
guac_iconv_read * remote_reader ;
476
479
const char * input = (char * ) format_data_response -> requestedFormatData ;
@@ -498,6 +501,7 @@ static UINT guac_rdp_cliprdr_format_data_response(CliprdrClientContext* cliprdr,
498
501
default :
499
502
guac_client_log (client , GUAC_LOG_DEBUG , "Requested clipboard data "
500
503
"in unsupported format (0x%X)." , clipboard -> requested_format );
504
+ guac_mem_free (received_data );
501
505
return CHANNEL_RC_OK ;
502
506
503
507
}
@@ -512,13 +516,15 @@ static UINT guac_rdp_cliprdr_format_data_response(CliprdrClientContext* cliprdr,
512
516
/* Convert, store, and forward the clipboard data received from RDP
513
517
* server */
514
518
if (guac_iconv (remote_reader , & input , data_len ,
515
- GUAC_WRITE_UTF8 , & output , sizeof ( received_data ) )) {
516
- int length = strnlen (received_data , sizeof ( received_data ) );
519
+ GUAC_WRITE_UTF8 , & output , output_buf_size )) {
520
+ int length = strnlen (received_data , output_buf_size );
517
521
guac_common_clipboard_reset (clipboard -> clipboard , "text/plain" );
518
522
guac_common_clipboard_append (clipboard -> clipboard , received_data , length );
519
523
guac_common_clipboard_send (clipboard -> clipboard , client );
520
524
}
521
525
526
+ guac_mem_free (received_data );
527
+
522
528
return CHANNEL_RC_OK ;
523
529
524
530
}
@@ -618,12 +624,12 @@ static void guac_rdp_cliprdr_channel_disconnected(rdpContext* context,
618
624
619
625
}
620
626
621
- guac_rdp_clipboard * guac_rdp_clipboard_alloc (guac_client * client ) {
627
+ guac_rdp_clipboard * guac_rdp_clipboard_alloc (guac_client * client , int buffer_size ) {
622
628
623
629
/* Allocate clipboard and underlying storage */
624
630
guac_rdp_clipboard * clipboard = guac_mem_zalloc (sizeof (guac_rdp_clipboard ));
625
631
clipboard -> client = client ;
626
- clipboard -> clipboard = guac_common_clipboard_alloc ();
632
+ clipboard -> clipboard = guac_common_clipboard_alloc (buffer_size );
627
633
clipboard -> requested_format = CF_TEXT ;
628
634
629
635
return clipboard ;
0 commit comments