[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

@@ -1999,7 +1999,8 @@ BOOL gcc_write_server_network_data(wStream* s, const rdpMcs* mcs)
{
WINPR_ASSERT(s);
WINPR_ASSERT(mcs);
const size_t payloadLen = 8 + mcs->channelCount * 2 + (mcs->channelCount % 2 == 1 ? 2 : 0);
const size_t payloadLen =
8ull + mcs->channelCount * 2ull + (mcs->channelCount % 2 == 1 ? 2ull : 0ull);
WINPR_ASSERT(payloadLen <= UINT16_MAX);
if (!gcc_write_user_data_header(s, SC_NET, (UINT16)payloadLen))

View File

@@ -3302,7 +3302,7 @@ size_t update_approximate_create_offscreen_bitmap_order(
deleteList = &(create_offscreen_bitmap->deleteList);
WINPR_ASSERT(deleteList);
return 32 + deleteList->cIndices * 2;
return 32ull + deleteList->cIndices * 2ull;
}
BOOL update_write_create_offscreen_bitmap_order(

View File

@@ -597,7 +597,7 @@ static BOOL http_proxy_connect(rdpContext* context, BIO* bufferedBio, const char
hostLen = strlen(hostname);
portLen = strnlen(port_str, sizeof(port_str));
reserveSize = strlen(connect) + (hostLen + 1 + portLen) * 2 + strlen(httpheader);
reserveSize = strlen(connect) + (hostLen + 1ull + portLen) * 2ull + strlen(httpheader);
s = Stream_New(NULL, reserveSize);
if (!s)
goto fail;