diff options
author | Armin Novak <anovak@thincast.com> | 2023-12-14 21:45:47 +0300 |
---|---|---|
committer | Armin Novak <anovak@thincast.com> | 2023-12-14 21:49:23 +0300 |
commit | 5c9adf6e599bc002ae6b15e464c21a72de6ba23f (patch) | |
tree | 4837413d4d986d3023201e6c2e120b1936854acb | |
parent | 53e9af8fbeaa28a8065a328e546dd9e8164def76 (diff) |
fix length calculation of utf-16 string
-rw-r--r-- | plugins/rdp/rdp_cliprdr.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/plugins/rdp/rdp_cliprdr.c b/plugins/rdp/rdp_cliprdr.c index 4f85fe5a2..0a847f45d 100644 --- a/plugins/rdp/rdp_cliprdr.c +++ b/plugins/rdp/rdp_cliprdr.c @@ -811,7 +811,7 @@ void remmina_rdp_cliprdr_get_clipboard_data(RemminaProtocolWidget *gp, RemminaPl WCHAR *outbuf_wchar = NULL; #endif GdkPixbuf *image = NULL; - int size = 0; + size_t size = 0; rfContext *rfi = GET_PLUGIN_DATA(gp); RemminaPluginRdpEvent rdp_event = { 0 }; @@ -851,12 +851,18 @@ void remmina_rdp_cliprdr_get_clipboard_data(RemminaProtocolWidget *gp, RemminaPl { size = strlen((const char *)inbuf); inbuf = lf2crlf(inbuf, &size); + { #if FREERDP_VERSION_MAJOR >= 3 - size *= sizeof(WCHAR); - outbuf_wchar = ConvertUtf8NToWCharAlloc((const char *)inbuf, (size_t)size, NULL); + size_t len = 0; + outbuf_wchar = ConvertUtf8NToWCharAlloc((const char *)inbuf, (size_t)size, &len); + size = len * sizeof(WCHAR); #else - size = (ConvertToUnicode(CP_UTF8, 0, (CHAR *)inbuf, -1, (WCHAR **)&outbuf, 0)) * sizeof(WCHAR); + const int rc = (ConvertToUnicode(CP_UTF8, 0, (CHAR *)inbuf, -1, (WCHAR **)&outbuf, 0)) * sizeof(WCHAR); + size = 0; + if (rc >= 0) + size = (size_t)rc; #endif + } g_free(inbuf); break; } @@ -898,7 +904,7 @@ void remmina_rdp_cliprdr_get_clipboard_data(RemminaProtocolWidget *gp, RemminaPl } rdp_event.type = REMMINA_RDP_EVENT_TYPE_CLIPBOARD_SEND_CLIENT_FORMAT_DATA_RESPONSE; - rdp_event.clipboard_formatdataresponse.size = size; + rdp_event.clipboard_formatdataresponse.size = (int)MIN(size, INT32_MAX); #if FREERDP_VERSION_MAJOR >= 3 // For unicode, use the wchar buffer |