snd_pcm_t* capture_handle)
{
int error;
+ SSIZE_T s;
UINT32 channels = alsa->aformat.nChannels;
snd_pcm_hw_params_t* hw_params;
snd_pcm_format_t format = audin_alsa_format(alsa->aformat.wFormatTag, alsa->aformat.wBitsPerSample);
snd_pcm_hw_params(capture_handle, hw_params);
snd_pcm_hw_params_free(hw_params);
snd_pcm_prepare(capture_handle);
- alsa->aformat.nChannels = channels;
- alsa->bytes_per_frame = snd_pcm_format_size(format, 1) * channels;
+ if (channels > UINT16_MAX)
+ return FALSE;
+ s = snd_pcm_format_size(format, 1);
+ if ((s < 0) || (s > UINT16_MAX))
+ return FALSE;
+ alsa->aformat.nChannels = (UINT16)channels;
+ alsa->bytes_per_frame = (size_t)s * channels;
return TRUE;
}
size_t cchInstallPrefix;
FREERDP_ADDIN** ppAddins;
WIN32_FIND_DATAA FindData;
- cchAddinPath = strlen(pszAddinPath);
- cchInstallPrefix = strlen(pszInstallPrefix);
+ cchAddinPath = strnlen(pszAddinPath, sizeof(FREERDP_ADDIN_PATH));
+ cchInstallPrefix = strnlen(pszInstallPrefix, sizeof(FREERDP_INSTALL_PREFIX));
pszExtension = PathGetSharedLibraryExtensionA(0);
- cchPattern = 128 + strlen(pszExtension) + 2;
+ cchPattern = 128 + strnlen(pszExtension, MAX_PATH) + 2;
pszPattern = (LPSTR) malloc(cchPattern + 1);
if (!pszPattern)
pszExtension);
}
- cchPattern = strlen(pszPattern);
+ cchPattern = strnlen(pszPattern, cchPattern);
cchSearchPath = cchInstallPrefix + cchAddinPath + cchPattern + 3;
pszSearchPath = (LPSTR) malloc(cchSearchPath + 1);
if (asciiNames)
{
if (szFormatName)
- formatNameLength = strlen(szFormatName);
+ formatNameLength = strnlen(szFormatName, 32);
if (formatNameLength > 31)
formatNameLength = 31;
return ERROR_INVALID_DATA;
}
- length = strlen(cliprdr->temporaryDirectory);
+ length = strnlen(cliprdr->temporaryDirectory, 520);
if (length > 519)
length = 519;
if (!base64)
goto fail;
- b64len = strlen(base64);
+ /* base64 char represents 6bit -> 4*(n/3) is the length which is
+ * always smaller than 2*n */
+ b64len = strnlen(base64, 2 * length);
rc = WriteFile(file, base64, b64len, &written, NULL);
if (b64len != written)
ChannelNameW[index] = (WCHAR) header->ChannelName[index];
}
- ChannelNameLen = (strlen(header->ChannelName) + 1) * 2;
+ ChannelNameLen = (strnlen(header->ChannelName, sizeof(header->ChannelName)) + 1) * 2;
Stream_Write_UINT32(s, ChannelNameLen); /* ChannelNameLen (4 bytes) */
Stream_Write_UINT32(s, header->DataLength); /* DataLen (4 bytes) */
Stream_Write(s, ChannelNameW, ChannelNameLen); /* ChannelName (variable) */
ChannelNameW[index] = (WCHAR) header->ChannelName[index];
}
- ChannelNameLen = (strlen(header->ChannelName) + 1) * 2;
+ ChannelNameLen = (strnlen(header->ChannelName, sizeof(header->ChannelName)) + 1) * 2;
Stream_Write_UINT32(s, ChannelNameLen); /* ChannelNameLen (4 bytes) */
Stream_Write_UINT32(s, header->DataLength); /* DataLen (4 bytes) */
Stream_Write(s, ChannelNameW, ChannelNameLen); /* ChannelName (variable) */
char* driver;
RDPDR_SERIAL* device;
#if defined __linux__ && !defined ANDROID
- int i, len;
+ size_t i, len;
SERIAL_DEVICE* serial;
#endif /* __linux__ */
UINT error = CHANNEL_RC_OK;
fwrite("P5\n", 1, 3, fp);
sprintf_s(buf, sizeof(buf), "%"PRIu32" %"PRIu32"\n", sample->stream->width,
sample->stream->height);
- fwrite(buf, 1, strlen(buf), fp);
+ fwrite(buf, 1, strnlen(buf, sizeof(buf)), fp);
fwrite("255\n", 1, 4, fp);
fwrite(sample->data, 1, sample->stream->width * sample->stream->height, fp);
fflush(fp);
return _strdup(settings->WindowTitle);
port = (settings->ServerPort != 3389);
- size = strlen(name) + 16;
+ /* Just assume a window title is never longer than a filename... */
+ size = strnlen(name, MAX_PATH) + 16;
windowTitle = calloc(size, sizeof(char));
if (!windowTitle)
/* draw an border for the floatbar */
XSetForeground(display, gc, xf_floatbar_get_color(floatbar, FLOATBAR_COLOR_BORDER));
XDrawLines(display, floatbar->handle, gc, border, 5, CoordModeOrigin);
- /* draw the host name connected to */
- len = strlen(floatbar->title);
+ /* draw the host name connected to (limit to maximum file name) */
+ len = strnlen(floatbar->title, MAX_PATH);
XSetForeground(display, gc, xf_floatbar_get_color(floatbar, FLOATBAR_COLOR_FOREGROUND));
XDrawString(display, floatbar->handle, gc, floatbar->width / 2 - len * 2, 15,
floatbar->title, len);
static void xf_SetWindowTitleText(xfContext* xfc, Window window, const char* name)
{
- const size_t i = strlen(name);
+ const size_t i = strnlen(name, MAX_PATH);
XStoreName(xfc->display, window, name);
Atom wm_Name = xfc->_NET_WM_NAME;
Atom utf8Str = xfc->UTF8_STRING;
static char* print_token(char* text, int start_offset, int* current, int limit,
const char delimiter)
{
- int len = (int)strlen(text);
+ size_t len = strlen(text);
if (*current < start_offset)
*current += printf("%*c", (start_offset - *current), ' ');
return -1;
}
- if (_stricmp(&(argv[index])[strlen(argv[index]) - 4], ".rdp") == 0)
+ if (_stricmp(&(argv[index])[strnlen(argv[index], 9) - 4], ".rdp") == 0)
{
return -1;
}
const size_t cchBaseFileName = sizeof(FREERDP_SHARED_LIBRARY_PREFIX) + 32;
LPCSTR pszExtension;
LPCSTR pszPrefix = FREERDP_SHARED_LIBRARY_PREFIX;
+ const size_t nameLen = strnlen(pszName, MAX_PATH);
+ const size_t subsystemLen = strnlen(pszSubsystem, MAX_PATH);
+ const size_t typeLen = strlen(pszType);
+ size_t extensionLen;
pszExtension = PathGetSharedLibraryExtensionA(0);
+ extensionLen = strnlen(pszExtension, MAX_PATH);
if (pszName && pszSubsystem && pszType)
{
- const size_t cchFileName = cchBaseFileName + strlen(pszName) + strlen(pszSubsystem) + strlen(
- pszType) + strlen(pszExtension);
+ const size_t cchFileName = cchBaseFileName + nameLen + subsystemLen + typeLen + extensionLen;
pszFileName = (LPSTR) malloc(cchFileName);
if (!pszFileName)
}
else if (pszName && pszSubsystem)
{
- const size_t cchFileName = cchBaseFileName + strlen(pszName) + strlen(pszSubsystem) + strlen(
- pszExtension);
+ const size_t cchFileName = cchBaseFileName + nameLen + subsystemLen + extensionLen;
pszFileName = (LPSTR) malloc(cchFileName);
if (!pszFileName)
}
else if (pszName)
{
- const size_t cchFileName = cchBaseFileName + strlen(pszName) + strlen(pszExtension);
+ const size_t cchFileName = cchBaseFileName + nameLen + extensionLen;
pszFileName = (LPSTR) malloc(cchFileName);
if (!pszFileName)
LPSTR pszEntryName;
size_t cchEntryName;
/* subsystem add-in */
- cchEntryName = 64 + strlen(pszName);
+ cchEntryName = 64 + nameLen;
pszEntryName = (LPSTR) malloc(cchEntryName + 1);
if (!pszEntryName)
int i;
char* p;
char* str;
- int length;
+ size_t length;
char** new_argv;
length = strlen(option) + strlen(value) + 1;
str = (char*) malloc(length + 1);
{
int i;
char* str;
- int length;
+ size_t length;
char** new_argv;
length = strlen(option) + strlen(value) + 1;
str = (char*) malloc(length + 1);
UINT error = CHANNEL_RC_OK;
int index;
char* hostname;
- int hostnameLength;
+ size_t hostnameLength;
rdpChannels* channels;
CHANNEL_CLIENT_DATA* pChannelClientData;
channels = instance->context->channels;
hostname = instance->settings->ServerHostname;
- hostnameLength = (int) strlen(hostname);
+ hostnameLength = strlen(hostname);
for (index = 0; index < channels->clientDataCount; index++)
{
UINT error = CHANNEL_RC_OK;
int index;
char* hostname;
- int hostnameLength;
+ size_t hostnameLength;
rdpChannels* channels;
CHANNEL_CLIENT_DATA* pChannelClientData;
channels = instance->context->channels;
hostname = instance->settings->ServerHostname;
- hostnameLength = (int) strlen(hostname);
+ hostnameLength = strlen(hostname);
for (index = 0; index < channels->clientDataCount; index++)
{
if ((c = *str2++) != '\0')
{
- len = strlen(str2);
+ len = strnlen(str2, slen + 1);
do
{
wStream* sChunk;
char chunkSize[11];
sprintf_s(chunkSize, sizeof(chunkSize), "%"PRIXz"\r\n", Stream_Length(sPacket));
- sChunk = Stream_New(NULL, strlen(chunkSize) + Stream_Length(sPacket) + 2);
+ sChunk = Stream_New(NULL, strnlen(chunkSize, sizeof(chunkSize)) + Stream_Length(sPacket) + 2);
if (!sChunk)
return FALSE;
- Stream_Write(sChunk, chunkSize, strlen(chunkSize));
+ Stream_Write(sChunk, chunkSize, strnlen(chunkSize, sizeof(chunkSize)));
Stream_Write(sChunk, Stream_Buffer(sPacket), Stream_Length(sPacket));
Stream_Write(sChunk, "\r\n", 2);
Stream_SealLength(sChunk);
return 0;
sprintf_s(chunkSize, sizeof(chunkSize), "%"PRIxz"\r\n", packetSize);
- sChunk = Stream_New(NULL, strlen(chunkSize) + packetSize + 2);
+ sChunk = Stream_New(NULL, strnlen(chunkSize, sizeof(chunkSize)) + packetSize + 2);
if (!sChunk)
return -1;
- Stream_Write(sChunk, chunkSize, strlen(chunkSize));
+ Stream_Write(sChunk, chunkSize, strnlen(chunkSize, sizeof(chunkSize)));
Stream_Write_UINT16(sChunk, PKT_TYPE_DATA); /* Type */
Stream_Write_UINT16(sChunk, 0); /* Reserved */
Stream_Write_UINT32(sChunk, (UINT32)packetSize); /* Packet length */
#include <winpr/stream.h>
-#define MCS_BASE_CHANNEL_ID 1001
-#define MCS_GLOBAL_CHANNEL_ID 1003
+#define MCS_BASE_CHANNEL_ID 1001
+#define MCS_GLOBAL_CHANNEL_ID 1003
enum MCS_Result
{
rdpMcsChannel* channels;
};
-#define MCS_SEND_DATA_HEADER_MAX_LENGTH 8
+#define MCS_SEND_DATA_HEADER_MAX_LENGTH 8
-#define MCS_TYPE_CONNECT_INITIAL 0x65
-#define MCS_TYPE_CONNECT_RESPONSE 0x66
+#define MCS_TYPE_CONNECT_INITIAL 0x65
+#define MCS_TYPE_CONNECT_RESPONSE 0x66
-FREERDP_LOCAL BOOL mcs_merge_domain_parameters(DomainParameters*
- targetParameters, DomainParameters* minimumParameters,
- DomainParameters* maximumParameters, DomainParameters* pOutParameters);
+FREERDP_LOCAL BOOL mcs_merge_domain_parameters(DomainParameters* targetParameters,
+ DomainParameters* minimumParameters,
+ DomainParameters* maximumParameters,
+ DomainParameters* pOutParameters);
-FREERDP_LOCAL BOOL mcs_write_connect_initial(wStream* s, rdpMcs* mcs,
- wStream* userData);
-FREERDP_LOCAL BOOL mcs_write_connect_response(wStream* s, rdpMcs* mcs,
- wStream* userData);
+FREERDP_LOCAL BOOL mcs_write_connect_initial(wStream* s, rdpMcs* mcs, wStream* userData);
+FREERDP_LOCAL BOOL mcs_write_connect_response(wStream* s, rdpMcs* mcs, wStream* userData);
FREERDP_LOCAL BOOL mcs_recv_connect_initial(rdpMcs* mcs, wStream* s);
FREERDP_LOCAL BOOL mcs_send_connect_initial(rdpMcs* mcs);
FREERDP_LOCAL BOOL mcs_send_attach_user_request(rdpMcs* mcs);
FREERDP_LOCAL BOOL mcs_recv_attach_user_confirm(rdpMcs* mcs, wStream* s);
FREERDP_LOCAL BOOL mcs_send_attach_user_confirm(rdpMcs* mcs);
-FREERDP_LOCAL BOOL mcs_recv_channel_join_request(rdpMcs* mcs, wStream* s,
- UINT16* channelId);
+FREERDP_LOCAL BOOL mcs_recv_channel_join_request(rdpMcs* mcs, wStream* s, UINT16* channelId);
FREERDP_LOCAL BOOL mcs_send_channel_join_request(rdpMcs* mcs, UINT16 channelId);
-FREERDP_LOCAL BOOL mcs_recv_channel_join_confirm(rdpMcs* mcs, wStream* s,
- UINT16* channelId);
+FREERDP_LOCAL BOOL mcs_recv_channel_join_confirm(rdpMcs* mcs, wStream* s, UINT16* channelId);
FREERDP_LOCAL BOOL mcs_send_channel_join_confirm(rdpMcs* mcs, UINT16 channelId);
-FREERDP_LOCAL BOOL mcs_recv_disconnect_provider_ultimatum(rdpMcs* mcs,
- wStream* s, int* reason);
+FREERDP_LOCAL BOOL mcs_recv_disconnect_provider_ultimatum(rdpMcs* mcs, wStream* s, int* reason);
FREERDP_LOCAL BOOL mcs_send_disconnect_provider_ultimatum(rdpMcs* mcs);
-FREERDP_LOCAL BOOL mcs_read_domain_mcspdu_header(wStream* s,
- enum DomainMCSPDU* domainMCSPDU, UINT16* length);
-FREERDP_LOCAL void mcs_write_domain_mcspdu_header(wStream* s,
- enum DomainMCSPDU domainMCSPDU, UINT16 length, BYTE options);
+FREERDP_LOCAL BOOL mcs_read_domain_mcspdu_header(wStream* s, enum DomainMCSPDU* domainMCSPDU,
+ UINT16* length);
+FREERDP_LOCAL void mcs_write_domain_mcspdu_header(wStream* s, enum DomainMCSPDU domainMCSPDU,
+ UINT16 length, BYTE options);
FREERDP_LOCAL BOOL mcs_client_begin(rdpMcs* mcs);
size_t pos, len;
BOOL result = FALSE;
BOOL isToken = FALSE;
+ size_t remain = Stream_GetRemainingLength(s);
str = Stream_Pointer(s);
pos = Stream_GetPosition(s);
/* minimum length for token is 15 */
- if (Stream_GetRemainingLength(s) < 15)
+ if (remain < 15)
return TRUE;
if (memcmp(Stream_Pointer(s), "Cookie: mstshash=", 17) != 0)
else
{
/* not a token, minimum length for cookie is 19 */
- if (Stream_GetRemainingLength(s) < 19)
+ if (remain < 19)
return TRUE;
Stream_Seek(s, 17);
}
- while (Stream_GetRemainingLength(s) >= 2)
+ while ((remain = Stream_GetRemainingLength(s)) >= 2)
{
Stream_Read_UINT16(s, crlf);
{
Stream_Rewind(s, 2);
len = Stream_GetPosition(s) - pos;
+ remain = Stream_GetRemainingLength(s);
Stream_Write_UINT16(s, 0);
- if (strlen((char*)str) == len)
+ if (strnlen((char*)str, remain) == len)
{
if (isToken)
result = nego_set_routing_token(nego, str, len);
if (flags & WTS_CHANNEL_OPTION_DYNAMIC)
return NULL; /* not yet supported */
- length = strlen(name);
+ length = strnlen(name, 9);
if (length > 8)
return NULL; /* SVC maximum name length is 8 */
Stream_Write(s, " HTTP/1.1" CRLF "Host: ", 17);
Stream_Write(s, hostname, strlen(hostname));
Stream_Write_UINT8(s, ':');
- Stream_Write(s, port_str, strlen(port_str));
+ Stream_Write(s, port_str, strnlen(port_str, sizeof (port_str)));
Stream_Write(s, CRLF CRLF, 4);
status = BIO_write(bufferedBio, Stream_Buffer(s), Stream_GetPosition(s));
*eol = '\0';
WLog_INFO(TAG, "HTTP Proxy: %s", recv_buf);
- if (strlen(recv_buf) < 12)
+ if (strnlen(recv_buf, sizeof(recv_buf)) < 12)
{
return FALSE;
}
static BOOL wts_write_drdynvc_create_request(wStream* s, UINT32 ChannelId,
const char* ChannelName)
{
- UINT32 len;
+ size_t len;
wts_write_drdynvc_header(s, CREATE_REQUEST_PDU, ChannelId);
- len = strlen(ChannelName) + 1;
+ len = strnlen(ChannelName, CHANNEL_NAME_LEN) + 1;
- if (!Stream_EnsureRemainingCapacity(s, (int) len))
+ if (!Stream_EnsureRemainingCapacity(s, len))
return FALSE;
Stream_Write(s, ChannelName, len);
{
UINT32 index;
- if (!mcs || !channel_name || !strlen(channel_name))
+ if (!mcs || !channel_name || !strnlen(channel_name, CHANNEL_NAME_LEN))
return NULL;
for (index = 0; index < mcs->channelCount; index++)
if (mcs->channels[index].joined)
{
if (_strnicmp(mcs->channels[index].Name, channel_name,
- strlen(channel_name)) == 0)
+ strnlen(channel_name, CHANNEL_NAME_LEN)) == 0)
return &mcs->channels[index];
}
}
HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId,
LPSTR pVirtualName)
{
- int length;
+ size_t length;
UINT32 index;
rdpMcs* mcs;
BOOL joined = FALSE;
NULL
};
char* commandLine = NULL;
- int commandLineLen;
+ size_t commandLineLen;
int argc = 4;
char* path = NULL;
char* wpath = NULL;
certdata->hostname = _strdup(hostname);
if (subject)
- certdata->subject = crypto_base64_encode((BYTE*)subject, strlen(subject));
+ certdata->subject = crypto_base64_encode((const BYTE*)subject, strlen(subject));
else
- certdata->subject = crypto_base64_encode((BYTE*)"", 0);
+ certdata->subject = crypto_base64_encode((const BYTE*)"", 0);
if (issuer)
- certdata->issuer = crypto_base64_encode((BYTE*)issuer, strlen(issuer));
+ certdata->issuer = crypto_base64_encode((const BYTE*)issuer, strlen(issuer));
else
- certdata->issuer = crypto_base64_encode((BYTE*)"", 0);
+ certdata->issuer = crypto_base64_encode((const BYTE*)"", 0);
certdata->fingerprint = _strdup(fingerprint);
for (i = 0; i < list.count; i ++)
{
result[i] = list.strings[i];
- (*lengths)[i] = strlen(result[i]);
+ (*lengths)[i] = strnlen(result[i], sizeof(*result));
}
string_list_free(&list);
const char* output;
};
-struct Encode64test encodeTests[] =
+static const struct Encode64test encodeTests[] =
{
{"\x00", 1, "AA=="},
{"\x00\x00", 2, "AAA="},
{NULL, -1, NULL}, /* /!\ last one /!\ */
};
-
int TestBase64(int argc, char* argv[])
{
int i, testNb = 0;
static int prepare(const char* currentFileV2, const char* legacyFileV2, const char* legacyFile)
{
- char* legacy[] =
+ const char* legacy[] =
{
"someurl ff:11:22:dd\r\n",
"otherurl aa:bb:cc:dd\r",
"legacyurl aa:bb:cc:dd\n"
};
- char* hosts[] =
+ const char* hosts[] =
{
"#somecomment\r\n"
"someurl 3389 ff:11:22:dd subject issuer\r\n"
if (!fl)
goto finish;
- for (i = 0; i < sizeof(hosts) / sizeof(hosts[0]); i++)
+ for (i = 0; i < ARRAYSIZE(hosts); i++)
{
if (fwrite(hosts[i], strlen(hosts[i]), 1, fl) != 1 ||
fwrite(hosts[i], strlen(hosts[i]), 1, fc) != 1)
if (!fl)
goto finish;
- for (i = 0; i < sizeof(legacy) / sizeof(legacy[0]); i++)
+ for (i = 0; i < ARRAYSIZE(legacy); i++)
{
if (fwrite(legacy[i], strlen(legacy[i]), 1, fl) != 1)
goto finish;
#else
static const char dirsep = '/';
#endif
- static const char* filename = "Test_x509_cert_info.pem";
+ static const char filename[] = "Test_x509_cert_info.pem";
const char* file = __FILE__;
const char* last_dirsep = strrchr(file, dirsep);
if (last_dirsep)
{
- char* result = malloc(last_dirsep - file + 1 + strlen(filename) + 1);
+ char* result = malloc(last_dirsep - file + 1 + strnlen(filename, sizeof(filename)) + 1);
strncpy(result, file, (last_dirsep - file + 1));
strcpy(result + (last_dirsep - file + 1), filename);
return result;
static int bio_rdp_tls_puts(BIO* bio, const char* str)
{
- int size;
+ size_t size;
int status;
if (!str)
static char* gdi_convert_postfix_to_infix(const char* postfix)
{
- int i;
- int length;
+ size_t i;
+ size_t length;
BOOL unary;
wStack* stack;
- int al, bl, cl, dl;
+ size_t al, bl, cl, dl;
char* a, *b, *c, *d;
bl = cl = dl = 0;
stack = Stack_New(FALSE);
found = FALSE;
CopyMemory(xkb_keyname, xkb->names->keys[i].name, 4);
- if (strlen(xkb_keyname) < 1)
+ if (strnlen(xkb_keyname, sizeof(xkb_keyname)) < 1)
continue;
for (j = 0; j < ARRAYSIZE(XKB_KEY_NAME_SCANCODE_TABLE); j++)
int rdtk_font_draw_text(rdtkSurface* surface, int nXDst, int nYDst, rdtkFont* font,
const char* text)
{
- int index;
- int length;
+ size_t index;
+ size_t length;
rdtkGlyph* glyph;
font = surface->engine->font;
length = strlen(text);
int rdtk_font_text_draw_size(rdtkFont* font, int* width, int* height, const char* text)
{
- int index;
- int length;
+ size_t index;
+ size_t length;
int glyphIndex;
rdtkGlyph* glyph;
*width = 0;
static int rdtk_font_convert_descriptor_code_to_utf8(const char* str, BYTE* utf8)
{
- int len = strlen(str);
+ size_t len = strlen(str);
*((UINT32*) utf8) = 0;
if (len < 1)
rdtkFont* rdtk_font_new(rdtkEngine* engine, const char* path, const char* file)
{
int status;
- int length;
+ size_t length;
rdtkFont* font = NULL;
char* fontBaseFile = NULL;
char* fontImageFile = NULL;
#define ROUTING_TOKEN_PREFIX "Cookie: msts="
char* colon;
size_t len;
- const size_t prefix_len = strlen(ROUTING_TOKEN_PREFIX);
+ const size_t prefix_len = strnlen(ROUTING_TOKEN_PREFIX, sizeof(ROUTING_TOKEN_PREFIX));
DWORD routing_token_length;
const char* routing_token = freerdp_nego_get_routing_token(context, &routing_token_length);
static int shadow_server_print_command_line_help(int argc, char** argv)
{
char* str;
- int length;
+ size_t length;
COMMAND_LINE_ARGUMENT_A* arg;
if (argc < 1)
if (arg->Format)
{
- length = (int)(strlen(arg->Name) + strlen(arg->Format) + 2);
+ length = (strlen(arg->Name) + strlen(arg->Format) + 2);
str = (char*) malloc(length + 1);
if (!str)
}
else if (arg->Flags & COMMAND_LINE_VALUE_BOOL)
{
- length = (int) strlen(arg->Name) + 32;
+ length = strlen(arg->Name) + 32;
str = (char*) malloc(length + 1);
if (!str)
body = strstr(pSrcData, "<BODY");
/* StartHTML */
- sprintf_s(num, sizeof(num), "%010"PRIuz"", strlen(pDstData));
+ sprintf_s(num, sizeof(num), "%010"PRIuz"", strnlen(pDstData, SrcSize + 200));
CopyMemory(&pDstData[23], num, 10);
if (!body)
strcat(pDstData, "<!--StartFragment-->");
/* StartFragment */
- sprintf_s(num, sizeof(num), "%010"PRIuz"", strlen(pDstData));
+ sprintf_s(num, sizeof(num), "%010"PRIuz"", strnlen(pDstData, SrcSize + 200));
CopyMemory(&pDstData[69], num, 10);
strcat(pDstData, pSrcData);
/* EndFragment */
- sprintf_s(num, sizeof(num), "%010"PRIuz"", strlen(pDstData));
+ sprintf_s(num, sizeof(num), "%010"PRIuz"", strnlen(pDstData, SrcSize + 200));
CopyMemory(&pDstData[93], num, 10);
strcat(pDstData, "<!--EndFragment-->");
strcat(pDstData, "</BODY></HTML>");
/* EndHTML */
- sprintf_s(num, sizeof(num), "%010"PRIuz"", strlen(pDstData));
+ sprintf_s(num, sizeof(num), "%010"PRIuz"", strnlen(pDstData, SrcSize + 200));
CopyMemory(&pDstData[43], num, 10);
*pSize = (UINT32) strlen(pDstData) + 1;
free(pSrcData);
return -1;
}
- SrcSize = (UINT32)(strlen(pSrcData) + 1);
+ SrcSize = (UINT32)(strnlen(pSrcData, UINT32_MAX - 1) + 1);
bSuccess = ClipboardSetData(clipboard, utf8StringFormatId, pSrcData,
SrcSize);
fprintf(stderr, "ClipboardSetData: %"PRId32"\n", bSuccess);
LPSTR CharUpperA(LPSTR lpsz)
{
- int i;
- int length;
+ size_t i;
+ size_t length;
if (!lpsz)
return NULL;
- length = (int) strlen(lpsz);
+ length = strlen(lpsz);
if (length < 1)
return (LPSTR) NULL;
LPSTR CharLowerA(LPSTR lpsz)
{
- int i;
- int length;
+ size_t i;
+ size_t length;
if (!lpsz)
return (LPSTR) NULL;
- length = (int) strlen(lpsz);
+ length = strlen(lpsz);
if (length < 1)
return (LPSTR) NULL;
static BYTE ru_Administrator_upper[] =
"\xd0\x90\xd0\x94\xd0\x9c\xd0\x98\xd0\x9d\xd0\x98\xd0\xa1\xd0\xa2\xd0\xa0\xd0\x90\xd0\xa2\xd0\x9e\xd0\xa0\x00";
-void string_hexdump(BYTE* data, int length)
+static void string_hexdump(const BYTE* data, size_t length)
{
- BYTE* p = data;
- int i, line, offset = 0;
+ const BYTE* p = data;
+ size_t i, line, offset = 0;
while (offset < length)
{
- printf("%04x ", offset);
+ printf("%04"PRIxz" ", offset);
line = length - offset;
}
}
-int convert_utf8_to_utf16(BYTE* lpMultiByteStr, BYTE* expected_lpWideCharStr, int expected_cchWideChar)
+static int convert_utf8_to_utf16(BYTE* lpMultiByteStr, BYTE* expected_lpWideCharStr, int expected_cchWideChar)
{
int rc = -1;
int length;
- int cbMultiByte;
+ size_t cbMultiByte;
int cchWideChar;
LPWSTR lpWideCharStr = NULL;
goto fail;
}
- lpWideCharStr = (LPWSTR) calloc(cchWideChar, sizeof(WCHAR));
+ lpWideCharStr = (LPWSTR) calloc((size_t)cchWideChar, sizeof(WCHAR));
if (!lpWideCharStr)
{
printf("MultiByteToWideChar: unable to allocate memory for test\n");
return rc;
}
-int convert_utf16_to_utf8(BYTE* lpWideCharStr, BYTE* expected_lpMultiByteStr, int expected_cbMultiByte)
+static int convert_utf16_to_utf8(BYTE* lpWideCharStr, BYTE* expected_lpMultiByteStr, int expected_cbMultiByte)
{
int rc = -1;
int length;
return rc;
}
-BOOL test_unicode_uppercasing(BYTE* lower, BYTE* upper)
+static BOOL test_unicode_uppercasing(BYTE* lower, BYTE* upper)
{
WCHAR* lowerW = NULL;
int lowerLength;
return TRUE;
}
-BOOL test_ConvertFromUnicode_wrapper()
+static BOOL test_ConvertFromUnicode_wrapper(void)
{
- BYTE src1[] = "\x52\x00\x49\x00\x43\x00\x48\x00\x20\x00\x54\x00\x45\x00\x58\x00\x54\x00\x20\x00\x46\x00\x4f\x00\x52\x00\x4d\x00\x41\x00\x54\x00\x40\x00\x40\x00\x40\x00";
- BYTE src2[] = "\x52\x00\x49\x00\x43\x00\x48\x00\x20\x00\x54\x00\x45\x00\x58\x00\x54\x00\x20\x00\x46\x00\x4f\x00\x52\x00\x4d\x00\x41\x00\x54\x00\x00\x00";
+ const BYTE src1[] = "\x52\x00\x49\x00\x43\x00\x48\x00\x20\x00\x54\x00\x45\x00\x58\x00\x54\x00\x20\x00\x46\x00\x4f\x00\x52\x00\x4d\x00\x41\x00\x54\x00\x40\x00\x40\x00\x40\x00";
+ const BYTE src2[] = "\x52\x00\x49\x00\x43\x00\x48\x00\x20\x00\x54\x00\x45\x00\x58\x00\x54\x00\x20\x00\x46\x00\x4f\x00\x52\x00\x4d\x00\x41\x00\x54\x00\x00\x00";
/* 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 */
- CHAR cmp0[] = { 'R','I','C','H',' ','T','E','X','T',' ','F','O','R','M','A','T', 0 };
+ const CHAR cmp0[] = { 'R','I','C','H',' ','T','E','X','T',' ','F','O','R','M','A','T', 0 };
CHAR* dst = NULL;
int i;
return FALSE;
}
-BOOL test_ConvertToUnicode_wrapper()
+static BOOL test_ConvertToUnicode_wrapper(void)
{
/* 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 */
- CHAR src1[] = { 'R','I','C','H',' ','T','E','X','T',' ','F','O','R','M','A','T','@','@','@' };
- CHAR src2[] = { 'R','I','C','H',' ','T','E','X','T',' ','F','O','R','M','A','T', 0 };
- BYTE cmp0[] = "\x52\x00\x49\x00\x43\x00\x48\x00\x20\x00\x54\x00\x45\x00\x58\x00\x54\x00\x20\x00\x46\x00\x4f\x00\x52\x00\x4d\x00\x41\x00\x54\x00\x00\x00";
+ const CHAR src1[] = { 'R','I','C','H',' ','T','E','X','T',' ','F','O','R','M','A','T','@','@','@' };
+ const CHAR src2[] = { 'R','I','C','H',' ','T','E','X','T',' ','F','O','R','M','A','T', 0 };
+ const BYTE cmp0[] = "\x52\x00\x49\x00\x43\x00\x48\x00\x20\x00\x54\x00\x45\x00\x58\x00\x54\x00\x20\x00\x46\x00\x4f\x00\x52\x00\x4d\x00\x41\x00\x54\x00\x00\x00";
WCHAR* dst = NULL;
- int i;
+ int ii;
+ size_t i;
/* Test unterminated unicode string:
* ConvertToUnicode must always null-terminate, even if the src string isn't
*/
printf("Input UTF8 String:\n");
- string_hexdump((BYTE*) src1, 19);
+ string_hexdump((const BYTE*) src1, 19);
- i = ConvertToUnicode(CP_UTF8, 0, src1, 16, &dst, 0);
- if (i != 16)
+ ii = ConvertToUnicode(CP_UTF8, 0, src1, 16, &dst, 0);
+ if (ii != 16)
{
- fprintf(stderr, "ConvertToUnicode failure A1: unexpectedly returned %d instead of 16\n", i);
+ fprintf(stderr, "ConvertToUnicode failure A1: unexpectedly returned %d instead of 16\n", ii);
goto fail;
}
+ i = (size_t)ii;
if (dst == NULL)
{
fprintf(stderr, "ConvertToUnicode failure A2: destination ist NULL\n");
fprintf(stderr, "ConvertToUnicode failure A3: dst length is %d instead of 16\n", i);
goto fail;
}
- if (_wcscmp(dst, (WCHAR*)cmp0))
+ if (_wcscmp(dst, (const WCHAR*)cmp0))
{
fprintf(stderr, "ConvertToUnicode failure A4: data mismatch\n");
goto fail;
}
printf("Output UTF16 String:\n");
- string_hexdump((BYTE*) dst, (i + 1) * sizeof(WCHAR));
+ string_hexdump((const BYTE*) dst, (i + 1) * sizeof(WCHAR));
free(dst);
dst = NULL;
/* Test null-terminated string */
printf("Input UTF8 String:\n");
- string_hexdump((BYTE*) src2, strlen(src2) + 1);
+ string_hexdump((const BYTE*) src2, strlen(src2) + 1);
i = ConvertToUnicode(CP_UTF8, 0, src2, -1, &dst, 0);
if (i != 17)
if (cbMultiByte == -1)
{
- size_t len = strlen((const char*) lpMultiByteStr);
+ size_t len = strnlen((const char*) lpMultiByteStr, INT32_MAX);
if (len >= INT32_MAX)
return 0;
cbMultiByte = (int)len + 1;
if (cbMultiByte == -1)
{
- size_t len = strlen(lpMultiByteStr);
+ size_t len = strnlen(lpMultiByteStr, INT_MAX);
if (len >= INT_MAX)
return 0;
cbMultiByte = (int)(len + 1);
memset(ibuf, 0, sizeof(ibuf));
memset(obuf, 0, sizeof(obuf));
- ilen = strlen(plaintext) + 1;
+ ilen = strnlen(plaintext, sizeof(plaintext)) + 1;
memcpy(ibuf, plaintext, ilen);
ilen = ((ilen + 15) / 16) * 16;
BYTE* text = NULL;
WINPR_RC4_CTX* ctx;
- len = strlen(TEST_RC4_PLAINTEXT);
+ len = strnlen(TEST_RC4_PLAINTEXT, sizeof(TEST_RC4_PLAINTEXT));
if (!(text = (BYTE*) calloc(1, len)))
{
goto out;
}
- if ((ctx = winpr_RC4_New(TEST_RC4_KEY, strlen((char*) TEST_RC4_KEY))) == NULL)
+ if ((ctx = winpr_RC4_New(TEST_RC4_KEY, strnlen((const char*)TEST_RC4_KEY, sizeof(TEST_RC4_KEY)))) == NULL)
{
fprintf(stderr, "%s: winpr_RC4_New failed\n", __FUNCTION__);
goto out;
}
- rc = winpr_RC4_Update(ctx, len, (BYTE*) TEST_RC4_PLAINTEXT, text);
+ rc = winpr_RC4_Update(ctx, len, (const BYTE*) TEST_RC4_PLAINTEXT, text);
winpr_RC4_Free(ctx);
if (!rc)
{
fprintf(stderr, "%s: winpr_Digest_Init failed\n", __FUNCTION__);
goto out;
}
- if (!winpr_Digest_Update(ctx, (BYTE*) TEST_MD5_DATA, strlen(TEST_MD5_DATA)))
+ if (!winpr_Digest_Update(ctx, (const BYTE*) TEST_MD5_DATA, strnlen(TEST_MD5_DATA, sizeof(TEST_MD5_DATA))))
{
fprintf(stderr, "%s: winpr_Digest_Update failed\n", __FUNCTION__);
goto out;
fprintf(stderr, "%s: winpr_Digest_Init failed\n", __FUNCTION__);
goto out;
}
- if (!winpr_Digest_Update(ctx, (BYTE*) TEST_MD4_DATA, strlen(TEST_MD4_DATA)))
+ if (!winpr_Digest_Update(ctx, (const BYTE*) TEST_MD4_DATA, strnlen(TEST_MD4_DATA, sizeof(TEST_MD4_DATA))))
{
fprintf(stderr, "%s: winpr_Digest_Update failed\n", __FUNCTION__);
goto out;
fprintf(stderr, "%s: winpr_Digest_Init failed\n", __FUNCTION__);
goto out;
}
- if (!winpr_Digest_Update(ctx, (BYTE*) TEST_SHA1_DATA, strlen(TEST_SHA1_DATA)))
+ if (!winpr_Digest_Update(ctx, (const BYTE*) TEST_SHA1_DATA, strnlen(TEST_SHA1_DATA, sizeof(TEST_SHA1_DATA))))
{
fprintf(stderr, "%s: winpr_Digest_Update failed\n", __FUNCTION__);
goto out;
fprintf(stderr, "%s: winpr_HMAC_Init failed\n", __FUNCTION__);
goto out;
}
- if (!winpr_HMAC_Update(ctx, (BYTE*) TEST_HMAC_MD5_DATA, strlen(TEST_HMAC_MD5_DATA)))
+ if (!winpr_HMAC_Update(ctx, (const BYTE*) TEST_HMAC_MD5_DATA, strnlen(TEST_HMAC_MD5_DATA, sizeof(TEST_HMAC_MD5_DATA))))
{
fprintf(stderr, "%s: winpr_HMAC_Update failed\n", __FUNCTION__);
goto out;
fprintf(stderr, "%s: winpr_HMAC_Init failed\n", __FUNCTION__);
goto out;
}
- if (!winpr_HMAC_Update(ctx, (BYTE*) TEST_HMAC_SHA1_DATA, strlen(TEST_HMAC_SHA1_DATA)))
+ if (!winpr_HMAC_Update(ctx, (const BYTE*) TEST_HMAC_SHA1_DATA, strnlen(TEST_HMAC_SHA1_DATA, sizeof(TEST_HMAC_SHA1_DATA))))
{
fprintf(stderr, "%s: winpr_HMAC_Update failed\n", __FUNCTION__);
goto out;
{
int cbPlainText;
int cbCipherText;
- char* pPlainText;
+ const char* pPlainText;
BYTE* pCipherText;
- pPlainText = (char*) SECRET_PASSWORD_TEST;
+ pPlainText = SECRET_PASSWORD_TEST;
cbPlainText = strlen(pPlainText) + 1;
cbCipherText = cbPlainText + (CRYPTPROTECTMEMORY_BLOCK_SIZE - (cbPlainText % CRYPTPROTECTMEMORY_BLOCK_SIZE));
printf("cbPlainText: %d cbCipherText: %d\n", cbPlainText, cbCipherText);
{
#if !defined(_UWP)
char* p;
- int offset;
- int length;
+ size_t offset;
+ size_t length;
char** envp;
DWORD cchEnvironmentBlock;
LPCH lpszEnvironmentBlock;
while (*envp)
{
- length = (int) strlen(*envp);
+ length = strlen(*envp);
- while ((offset + length + 8) > (int) cchEnvironmentBlock)
+ while ((offset + length + 8) > cchEnvironmentBlock)
{
DWORD new_size;
LPCH new_blk;
{
const char* cp;
char* p;
- int offset;
- int length;
+ size_t offset;
+ size_t length;
const char* envp;
DWORD cchEnvironmentBlock;
LPCH lpszEnvironmentBlock;
const char** mergeStrings;
- int mergeStringLength;
- int mergeArraySize = 128;
- int run;
- int mergeLength;
- int foundMerge;
+ size_t mergeStringLength;
+ size_t mergeArraySize = 128;
+ size_t run;
+ size_t mergeLength;
+ size_t foundMerge;
char* foundEquals;
mergeStrings = (LPCSTR*) calloc(mergeArraySize, sizeof(char*));
while (*cp && *(cp + 1))
{
- length = (int) strlen(cp);
+ length = strlen(cp);
if (mergeStringLength == mergeArraySize)
{
while ((original != NULL) && (*envp && *(envp+1)))
{
- ULONG old_offset = offset;
- length = (int) strlen(envp);
+ size_t old_offset = offset;
+ length = strlen(envp);
- while ((offset + length + 8) > (int) cchEnvironmentBlock)
+ while ((offset + length + 8) > cchEnvironmentBlock)
{
LPCH tmp;
cchEnvironmentBlock *= 2;
if (!mergeStrings[run])
continue;
- mergeLength = (int) strlen(mergeStrings[run]);
+ mergeLength = strlen(mergeStrings[run]);
foundEquals = strstr(mergeStrings[run], "=");
if (!foundEquals)
}
else
{
- while ((offset + mergeLength + 8) > (int) cchEnvironmentBlock)
+ while ((offset + mergeLength + 8) > cchEnvironmentBlock)
{
LPCH tmp;
cchEnvironmentBlock *= 2;
if (!mergeStrings[run])
continue;
- mergeLength = (int) strlen(mergeStrings[run]);
+ mergeLength = strlen(mergeStrings[run]);
- while ((offset + mergeLength + 8) > (int) cchEnvironmentBlock)
+ while ((offset + mergeLength + 8) > cchEnvironmentBlock)
{
LPCH tmp;
cchEnvironmentBlock *= 2;
DWORD GetEnvironmentVariableEBA(LPCSTR envBlock, LPCSTR lpName, LPSTR lpBuffer, DWORD nSize)
{
- int vLength = 0;
+ size_t vLength = 0;
char* env = NULL;
char* foundEquals;
const char* penvb = envBlock;
- int nLength, fLength, lpNameLength;
+ size_t nLength, fLength, lpNameLength;
if (!lpName || NULL == envBlock)
return 0;
- lpNameLength = (int) strlen(lpName);
+ lpNameLength = strlen(lpName);
if (lpNameLength < 1)
return 0;
while (*penvb && *(penvb + 1))
{
- fLength = (int) strlen(penvb);
+ fLength = strlen(penvb);
foundEquals = strstr(penvb,"=");
if (!foundEquals)
return 0;
}
- nLength = (int) (foundEquals - penvb);
+ nLength = (foundEquals - penvb);
if (nLength != lpNameLength)
{
if (!env)
return 0;
- vLength = (int) strlen(env);
+ vLength = strlen(env);
- if ((vLength + 1 > (int) nSize) || (!lpBuffer))
+ if ((vLength + 1 > nSize) || (!lpBuffer))
return vLength + 1;
CopyMemory(lpBuffer, env, vLength + 1);
char** EnvironmentBlockToEnvpA(LPCH lpszEnvironmentBlock)
{
char* p;
- int index;
- int count;
- int length;
+ SSIZE_T index;
+ size_t count;
+ size_t length;
char** envp = NULL;
count = 0;
while (p[0] && p[1])
{
- length = (int) strlen(p);
+ length = strlen(p);
p += (length + 1);
count++;
}
while (p[0] && p[1])
{
- length = (int) strlen(p);
+ length = strlen(p);
envp[index] = _strdup(p);
if (!envp[index])
{
{
#ifndef _WIN32
TCHAR* p;
- int length;
+ size_t length;
LPTCH lpszEnvironmentBlock;
LPTCH lpsz2Merge = "SHELL=123\0test=1\0test1=2\0DISPLAY=:77\0\0";
LPTCH lpszMergedEnvironmentBlock;
nSize = GetEnvironmentVariableA(TEST_NAME, NULL, 0);
/* check if value returned is len + 1 ) */
- if (nSize != strlen(TEST_VALUE) + 1)
+ if (nSize != strnlen(TEST_VALUE, sizeof(TEST_VALUE)) + 1)
{
printf("GetEnvironmentVariableA not found error\n");
return -1;
nSize = GetEnvironmentVariableA(TEST_NAME, lpBuffer, nSize);
- if (nSize != strlen(TEST_VALUE))
+ if (nSize != strnlen(TEST_VALUE, sizeof(TEST_VALUE)))
{
printf("GetEnvironmentVariableA wrong size returned\n");
goto fail;
if (!IsNamedPipeFileNameA(lpName))
return NULL;
- lpFileName = _strdup(&lpName[strlen(NAMED_PIPE_PREFIX_PATH)]);
+ lpFileName = _strdup(&lpName[strnlen(NAMED_PIPE_PREFIX_PATH, sizeof(NAMED_PIPE_PREFIX_PATH))]);
return lpFileName;
}
int TestFileGetStdHandle(int argc, char* argv[])
{
HANDLE so;
- char *buf = "happy happy";
+ const char buf[] = "happy happy";
DWORD bytesWritten;
so = GetStdHandle(STD_OUTPUT_HANDLE);
fprintf(stderr, "GetStdHandle failed ;(\n");
return -1;
}
- WriteFile(so, buf, strlen(buf), &bytesWritten, FALSE);
- if (bytesWritten != strlen(buf))
+ WriteFile(so, buf, strnlen(buf, sizeof(buf)), &bytesWritten, FALSE);
+ if (bytesWritten != strnlen(buf, sizeof (buf)))
{
fprintf(stderr, "write failed\n");
return -1;
if (strncmp(lpName, DEVICE_FILE_PREFIX_PATH, sizeof(DEVICE_FILE_PREFIX_PATH) - 1) != 0)
return NULL;
- lpFileName = _strdup(&lpName[strlen(DEVICE_FILE_PREFIX_PATH)]);
+ lpFileName = _strdup(&lpName[strnlen(DEVICE_FILE_PREFIX_PATH, sizeof (DEVICE_FILE_PREFIX_PATH))]);
return lpFileName;
}
}
buffer[status] = '\0';
- length = strlen(buffer);
+ length = strnlen(buffer, sizeof(buffer));
if (length < nSize)
{
* so use realpath to find the absolute, canonical path.
*/
realpath(path, buffer);
- length = strlen(buffer);
+ length = strnlen(buffer, sizeof(buffer));
if (length < nSize)
{
}
else if (pValue->type == REG_SZ)
{
- int length;
+ size_t length;
char* pData = (char*) lpData;
- length = (int) strlen(pValue->data.string);
+ length = strnlen(pValue->data.string, UINT32_MAX);
if (pData != NULL)
{
pData[length] = '\0';
}
- *lpcbData = length;
+ *lpcbData = (UINT32)length;
return ERROR_SUCCESS;
}
LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs)
{
char* p;
- int length;
+ size_t length;
char* pBeg;
char* pEnd;
char* buffer;
char* pOutput;
int numArgs = 0;
LPSTR* pArgs;
- int maxNumArgs;
- int maxBufferSize;
- int cmdLineLength;
+ size_t maxNumArgs;
+ size_t maxBufferSize;
+ size_t cmdLineLength;
BOOL* lpEscapedChars;
LPSTR lpEscapedCmdLine;
pArgs = NULL;
lpEscapedCmdLine = NULL;
- cmdLineLength = (int) strlen(lpCmdLine);
+ cmdLineLength = strlen(lpCmdLine);
lpEscapedChars = (BOOL*) calloc(cmdLineLength + 1, sizeof(BOOL));
if (!lpEscapedChars)
if (strstr(lpCmdLine, "\\\""))
{
- int i, n;
+ size_t i;
+ size_t n;
char* pLastEnd = NULL;
lpEscapedCmdLine = (char*) calloc(cmdLineLength + 1, sizeof(char));
if (!pBeg)
{
- length = (int) strlen(p);
+ length = strlen(p);
CopyMemory(pOutput, p, length);
pOutput += length;
break;
pBeg--;
}
- n = (int)((pEnd - pBeg) - 1);
- length = (int)(pBeg - pLastEnd);
+ n = ((pEnd - pBeg) - 1);
+ length = (pBeg - pLastEnd);
CopyMemory(pOutput, p, length);
pOutput += length;
p += length;
*pOutput++ = '\0';
lpCmdLine = (LPCSTR) lpEscapedCmdLine;
- cmdLineLength = (int) strlen(lpCmdLine);
+ cmdLineLength = strlen(lpCmdLine);
}
maxNumArgs = 2;
if (*p != '"')
{
/* no whitespace escaped with double quotes */
- length = (int)(p - pBeg);
+ length = (p - pBeg);
CopyMemory(pOutput, pBeg, length);
pOutput[length] = '\0';
pArgs[numArgs++] = pOutput;
{
FILE* fp;
wStream* s;
- int MessageLength;
- int FileNameLength;
- int FunctionNameLength;
- int TextStringLength;
+ size_t MessageLength;
+ size_t FileNameLength;
+ size_t FunctionNameLength;
+ size_t TextStringLength;
BOOL ret = TRUE;
wLogBinaryAppender* binaryAppender;
if (!fp)
return FALSE;
- FileNameLength = (int) strlen(message->FileName);
- FunctionNameLength = (int) strlen(message->FunctionName);
- TextStringLength = (int) strlen(message->TextString);
+ FileNameLength = strlen(message->FileName);
+ FunctionNameLength = strlen(message->FunctionName);
+ TextStringLength = strlen(message->TextString);
MessageLength = 16 +
(4 + FileNameLength + 1) +
(4 + FunctionNameLength + 1) +
(4 + TextStringLength + 1);
+ if ((MessageLength > UINT32_MAX) || (FileNameLength > UINT32_MAX) || (FunctionNameLength > UINT32_MAX) || (TextStringLength > UINT32_MAX))
+ return FALSE;
+
s = Stream_New(NULL, MessageLength);
if (!s)
return FALSE;
- Stream_Write_UINT32(s, MessageLength);
+ Stream_Write_UINT32(s, (UINT32)MessageLength);
Stream_Write_UINT32(s, message->Type);
Stream_Write_UINT32(s, message->Level);
Stream_Write_UINT32(s, message->LineNumber);
- Stream_Write_UINT32(s, FileNameLength);
+ Stream_Write_UINT32(s, (UINT32)FileNameLength);
Stream_Write(s, message->FileName, FileNameLength + 1);
- Stream_Write_UINT32(s, FunctionNameLength);
+ Stream_Write_UINT32(s, (UINT32)FunctionNameLength);
Stream_Write(s, message->FunctionName, FunctionNameLength + 1);
- Stream_Write_UINT32(s, TextStringLength);
+ Stream_Write_UINT32(s, (UINT32)TextStringLength);
Stream_Write(s, message->TextString, TextStringLength + 1);
Stream_SealLength(s);