[allocations] fix growth of preallocated buffers

* Replace * 2 with * sizeof(WCHAR) for string usages
* Grow streams and other buffers reasonably, e.g. add 128 elements per
  try and check for possible overflows
* Add constant postfix to force them to 64bit
This commit is contained in:
Armin Novak
2026-02-17 12:05:42 +01:00
parent fac35c3abb
commit 118afc0b95
28 changed files with 154 additions and 105 deletions

View File

@@ -36,7 +36,7 @@ UINT remdesk_write_channel_header(wStream* s, const REMDESK_CHANNEL_HEADER* head
}
const size_t ChannelNameLen =
(strnlen(header->ChannelName, sizeof(header->ChannelName)) + 1) * 2;
(strnlen(header->ChannelName, sizeof(header->ChannelName)) + 1) * sizeof(WCHAR);
WINPR_ASSERT(ChannelNameLen <= ARRAYSIZE(header->ChannelName));
Stream_Write_UINT32(s, (UINT32)ChannelNameLen); /* ChannelNameLen (4 bytes) */

View File

@@ -185,7 +185,7 @@ static UINT remdesk_recv_ctl_remote_control_desktop_pdu(RemdeskServerContext* co
return ERROR_INVALID_DATA;
cchStringW++;
const size_t cbRaConnectionStringW = cchStringW * 2;
const size_t cbRaConnectionStringW = cchStringW * sizeof(WCHAR);
pdu.raConnectionString =
ConvertWCharNToUtf8Alloc(raConnectionStringW, cbRaConnectionStringW / sizeof(WCHAR), NULL);
if (!pdu.raConnectionString)
@@ -240,7 +240,7 @@ static UINT remdesk_recv_ctl_authenticate_pdu(WINPR_ATTR_UNUSED RemdeskServerCon
return ERROR_INVALID_DATA;
cchStringW++;
const size_t cbExpertBlobW = cchStringW * 2;
const size_t cbExpertBlobW = cchStringW * sizeof(WCHAR);
pdu.raConnectionString =
ConvertWCharNToUtf8Alloc(raConnectionStringW, cbRaConnectionStringW / sizeof(WCHAR), NULL);
if (!pdu.raConnectionString)