UINT16 cbClientDir;
UINT16 cbAutoReconnectLen;
rdpSettings* settings = rdp->settings;
- WCHAR* wstr;
+ union {
+ BYTE* bp;
+ WCHAR* wp;
+ } ptrconv;
if (Stream_GetRemainingLength(s) < 4)
return FALSE;
if (cbClientAddress)
{
- wstr = (WCHAR*)Stream_Pointer(s);
+ ptrconv.bp = Stream_Pointer(s);
- if (wstr[cbClientAddress / 2 - 1])
+ if (ptrconv.wp[cbClientAddress / 2 - 1])
{
WLog_ERR(TAG, "protocol error: clientAddress must be null terminated");
return FALSE;
}
- if (ConvertFromUnicode(CP_UTF8, 0, wstr, -1, &settings->ClientAddress, 0, NULL, NULL) < 1)
+ if (ConvertFromUnicode(CP_UTF8, 0, ptrconv.wp, -1, &settings->ClientAddress, 0, NULL,
+ NULL) < 1)
{
WLog_ERR(TAG, "failed to convert client address");
return FALSE;
if (cbClientDir)
{
- wstr = (WCHAR*)Stream_Pointer(s);
+ ptrconv.bp = Stream_Pointer(s);
- if (wstr[cbClientDir / 2 - 1])
+ if (ptrconv.wp[cbClientDir / 2 - 1])
{
WLog_ERR(TAG, "protocol error: clientDir must be null terminated");
return FALSE;
}
- if (ConvertFromUnicode(CP_UTF8, 0, (WCHAR*)Stream_Pointer(s), -1, &settings->ClientDir, 0,
- NULL, NULL) < 1)
+ if (ConvertFromUnicode(CP_UTF8, 0, ptrconv.wp, -1, &settings->ClientDir, 0, NULL, NULL) < 1)
{
WLog_ERR(TAG, "failed to convert client directory");
return FALSE;
UINT16 cbWorkingDir;
UINT32 CompressionLevel;
rdpSettings* settings = rdp->settings;
- WCHAR* wstr;
+ union {
+ BYTE* bp;
+ WCHAR* wp;
+ } ptrconv;
if (Stream_GetRemainingLength(s) < 18)
return FALSE;
return FALSE;
}
- wstr = (WCHAR*)Stream_Pointer(s);
+ ptrconv.bp = Stream_Pointer(s);
- if (wstr[cbDomain / 2])
+ if (ptrconv.wp[cbDomain / 2])
{
WLog_ERR(TAG, "protocol error: Domain must be null terminated");
return FALSE;
}
- if (ConvertFromUnicode(CP_UTF8, 0, wstr, -1, &settings->Domain, 0, NULL, NULL) < 1)
+ if (ConvertFromUnicode(CP_UTF8, 0, ptrconv.wp, -1, &settings->Domain, 0, NULL, NULL) < 1)
{
WLog_ERR(TAG, "failed to convert Domain string");
return FALSE;
return FALSE;
}
- wstr = (WCHAR*)Stream_Pointer(s);
+ ptrconv.bp = Stream_Pointer(s);
- if (wstr[cbUserName / 2])
+ if (ptrconv.wp[cbUserName / 2])
{
WLog_ERR(TAG, "protocol error: UserName must be null terminated");
return FALSE;
}
- if (ConvertFromUnicode(CP_UTF8, 0, wstr, -1, &settings->Username, 0, NULL, NULL) < 1)
+ if (ConvertFromUnicode(CP_UTF8, 0, ptrconv.wp, -1, &settings->Username, 0, NULL, NULL) < 1)
{
WLog_ERR(TAG, "failed to convert UserName string");
return FALSE;
return FALSE;
}
- wstr = (WCHAR*)Stream_Pointer(s);
+ ptrconv.bp = Stream_Pointer(s);
- if (wstr[cbPassword / 2])
+ if (ptrconv.wp[cbPassword / 2])
{
WLog_ERR(TAG, "protocol error: Password must be null terminated");
return FALSE;
}
- if (ConvertFromUnicode(CP_UTF8, 0, wstr, -1, &settings->Password, 0, NULL, NULL) < 1)
+ if (ConvertFromUnicode(CP_UTF8, 0, ptrconv.wp, -1, &settings->Password, 0, NULL, NULL) < 1)
{
WLog_ERR(TAG, "failed to convert Password string");
return FALSE;
return FALSE;
}
- wstr = (WCHAR*)Stream_Pointer(s);
+ ptrconv.bp = Stream_Pointer(s);
- if (wstr[cbAlternateShell / 2])
+ if (ptrconv.wp[cbAlternateShell / 2])
{
WLog_ERR(TAG, "protocol error: AlternateShell must be null terminated");
return FALSE;
}
- if (ConvertFromUnicode(CP_UTF8, 0, wstr, -1, &settings->AlternateShell, 0, NULL, NULL) < 1)
+ if (ConvertFromUnicode(CP_UTF8, 0, ptrconv.wp, -1, &settings->AlternateShell, 0, NULL,
+ NULL) < 1)
{
WLog_ERR(TAG, "failed to convert AlternateShell string");
return FALSE;
return FALSE;
}
- wstr = (WCHAR*)Stream_Pointer(s);
+ ptrconv.bp = Stream_Pointer(s);
- if (wstr[cbWorkingDir / 2])
+ if (ptrconv.wp[cbWorkingDir / 2])
{
WLog_ERR(TAG, "protocol error: WorkingDir must be null terminated");
return FALSE;
}
- if (ConvertFromUnicode(CP_UTF8, 0, wstr, -1, &settings->ShellWorkingDirectory, 0, NULL,
- NULL) < 1)
+ if (ConvertFromUnicode(CP_UTF8, 0, ptrconv.wp, -1, &settings->ShellWorkingDirectory, 0,
+ NULL, NULL) < 1)
{
WLog_ERR(TAG, "failed to convert AlternateShell string");
return FALSE;
{
if (settings->RedirectionPassword && settings->RedirectionPasswordLength > 0)
{
+ union {
+ BYTE* bp;
+ WCHAR* wp;
+ } ptrconv;
if (settings->RedirectionPasswordLength > UINT16_MAX)
return FALSE;
usedPasswordCookie = TRUE;
- passwordW = (WCHAR*)settings->RedirectionPassword;
+ ptrconv.bp = settings->RedirectionPassword;
+ passwordW = ptrconv.wp;
cbPassword = (UINT16)settings->RedirectionPasswordLength;
}
else
{
UINT32 cbDomain;
UINT32 cbUserName;
- WCHAR* wstr;
+ union {
+ BYTE* bp;
+ WCHAR* wp;
+ } ptrconv;
+
+ WINPR_UNUSED(rdp);
ZeroMemory(info, sizeof(*info));
if (Stream_GetRemainingLength(s) < 576)
goto fail;
}
- wstr = (WCHAR*)Stream_Pointer(s);
+ ptrconv.bp = Stream_Pointer(s);
- if (wstr[cbDomain / 2 - 1])
+ if (ptrconv.wp[cbDomain / 2 - 1])
{
WLog_ERR(TAG, "protocol error: Domain must be null terminated");
goto fail;
}
- if (ConvertFromUnicode(CP_UTF8, 0, wstr, -1, &info->domain, 0, NULL, FALSE) < 1)
+ if (ConvertFromUnicode(CP_UTF8, 0, ptrconv.wp, -1, &info->domain, 0, NULL, FALSE) < 1)
{
WLog_ERR(TAG, "failed to convert the Domain string");
goto fail;
goto fail;
}
- wstr = (WCHAR*)Stream_Pointer(s);
+ ptrconv.bp = Stream_Pointer(s);
- if (wstr[cbUserName / 2 - 1])
+ if (ptrconv.wp[cbUserName / 2 - 1])
{
WLog_ERR(TAG, "protocol error: UserName must be null terminated");
goto fail;
}
- if (ConvertFromUnicode(CP_UTF8, 0, wstr, -1, &info->username, 0, NULL, FALSE) < 1)
+ if (ConvertFromUnicode(CP_UTF8, 0, ptrconv.wp, -1, &info->username, 0, NULL, FALSE) < 1)
{
WLog_ERR(TAG, "failed to convert the UserName string");
goto fail;
UINT32 Size;
UINT32 cbDomain;
UINT32 cbUserName;
- WCHAR* wstr;
+ union {
+ BYTE* bp;
+ WCHAR* wp;
+ } ptrconv;
+
+ WINPR_UNUSED(rdp);
ZeroMemory(info, sizeof(*info));
if (Stream_GetRemainingLength(s) < 576)
goto fail;
}
- wstr = (WCHAR*)Stream_Pointer(s);
+ ptrconv.bp = Stream_Pointer(s);
- if (wstr[cbDomain / 2 - 1])
+ if (ptrconv.wp[cbDomain / 2 - 1])
{
WLog_ERR(TAG, "protocol error: Domain field must be null terminated");
goto fail;
}
- if (ConvertFromUnicode(CP_UTF8, 0, wstr, -1, &info->domain, 0, NULL, FALSE) < 1)
+ if (ConvertFromUnicode(CP_UTF8, 0, ptrconv.wp, -1, &info->domain, 0, NULL, FALSE) < 1)
{
WLog_ERR(TAG, "failed to convert the Domain string");
goto fail;
goto fail;
}
- wstr = (WCHAR*)Stream_Pointer(s);
+ ptrconv.bp = Stream_Pointer(s);
- if (wstr[cbUserName / 2 - 1])
+ if (ptrconv.wp[cbUserName / 2 - 1])
{
WLog_ERR(TAG, "protocol error: UserName field must be null terminated");
goto fail;
}
- if (ConvertFromUnicode(CP_UTF8, 0, wstr, -1, &info->username, 0, NULL, FALSE) < 1)
+ if (ConvertFromUnicode(CP_UTF8, 0, ptrconv.wp, -1, &info->username, 0, NULL, FALSE) < 1)
{
WLog_ERR(TAG, "failed to convert the Domain string");
goto fail;
static BOOL rdp_recv_logon_plain_notify(rdpRdp* rdp, wStream* s)
{
+ WINPR_UNUSED(rdp);
if (Stream_GetRemainingLength(s) < 576)
return FALSE;
static BOOL rdp_write_logon_info_v1(wStream* s, logon_info* info)
{
- int sz = 4 + 52 + 4 + 512 + 4;
- int len;
+ size_t sz = 4 + 52 + 4 + 512 + 4;
+ int ilen;
+ UINT32 len;
WCHAR* wString = NULL;
if (!Stream_EnsureRemainingCapacity(s, sz))
return FALSE;
/* domain */
- len = ConvertToUnicode(CP_UTF8, 0, info->domain, -1, &wString, 0);
+ ilen = ConvertToUnicode(CP_UTF8, 0, info->domain, -1, &wString, 0);
- if (len < 0)
+ if (ilen < 0)
return FALSE;
- len *= 2;
+ len = (UINT32)ilen * 2;
if (len > 52)
{
free(wString);
/* username */
wString = NULL;
- len = ConvertToUnicode(CP_UTF8, 0, info->username, -1, &wString, 0);
+ ilen = ConvertToUnicode(CP_UTF8, 0, info->username, -1, &wString, 0);
- if (len < 0)
+ if (ilen < 0)
return FALSE;
- len *= 2;
+ len = (UINT32)ilen * 2;
if (len > 512)
{
static BOOL rdp_write_logon_info_v2(wStream* s, logon_info* info)
{
- int Size = 2 + 4 + 4 + 4 + 4 + 558;
- int domainLen, usernameLen, len;
+ UINT32 Size = 2 + 4 + 4 + 4 + 4 + 558;
+ size_t domainLen, usernameLen;
+ int len;
WCHAR* wString = NULL;
if (!Stream_EnsureRemainingCapacity(s, Size))
Stream_Write_UINT32(s, Size);
Stream_Write_UINT32(s, info->sessionId);
domainLen = strlen(info->domain);
- Stream_Write_UINT32(s, (domainLen + 1) * 2);
+ if (domainLen > UINT32_MAX)
+ return FALSE;
+ Stream_Write_UINT32(s, (UINT32)(domainLen + 1) * 2);
usernameLen = strlen(info->username);
- Stream_Write_UINT32(s, (usernameLen + 1) * 2);
+ if (usernameLen > UINT32_MAX)
+ return FALSE;
+ Stream_Write_UINT32(s, (UINT32)(usernameLen + 1) * 2);
Stream_Seek(s, 558);
len = ConvertToUnicode(CP_UTF8, 0, info->domain, -1, &wString, 0);
if (len < 0)
return FALSE;
- Stream_Write(s, wString, len * 2);
+ Stream_Write(s, wString, (size_t)len * 2);
free(wString);
wString = NULL;
len = ConvertToUnicode(CP_UTF8, 0, info->username, -1, &wString, 0);
if (len < 0)
return FALSE;
- Stream_Write(s, wString, len * 2);
+ Stream_Write(s, wString, (size_t)len * 2);
free(wString);
return TRUE;
}