Fixed TS_INFO_PACKET (#5275)

Those fields exclude the length of the mandatory null terminator:
* cbDomain
* cbUserName
* cbPassword
* cbAlternateShell
* cbWorkingDir
This commit is contained in:
Jiajun Wang 2019-02-23 00:31:42 +08:00 committed by akallabeth
parent 1b0ed37dce
commit fd27451768

View File

@ -772,6 +772,9 @@ static void rdp_write_info_packet(rdpRdp* rdp, wStream* s)
cbDomain = 0;
}
/* excludes (!) the length of the mandatory null terminator */
cbDomain = cbDomain >= 2 ? cbDomain - 2 : cbDomain;
if (!settings->RemoteAssistanceMode)
{
cbUserName = ConvertToUnicode(CP_UTF8, 0, settings->Username, -1, &userNameW, 0) * 2;
@ -782,13 +785,16 @@ static void rdp_write_info_packet(rdpRdp* rdp, wStream* s)
cbUserName = ConvertToUnicode(CP_UTF8, 0, settings->Username, -1, &userNameW, 0) * 2;
}
/* excludes (!) the length of the mandatory null terminator */
cbUserName = cbUserName >= 2 ? cbUserName - 2 : cbUserName;
if (!settings->RemoteAssistanceMode)
{
if (settings->RedirectionPassword && settings->RedirectionPasswordLength > 0)
{
usedPasswordCookie = TRUE;
passwordW = (WCHAR*) settings->RedirectionPassword;
cbPassword = settings->RedirectionPasswordLength - 2; /* Strip double zero termination */
cbPassword = settings->RedirectionPasswordLength;
}
else
{
@ -801,6 +807,9 @@ static void rdp_write_info_packet(rdpRdp* rdp, wStream* s)
cbPassword = ConvertToUnicode(CP_UTF8, 0, "*", -1, &passwordW, 0) * 2;
}
/* excludes (!) the length of the mandatory null terminator */
cbPassword = cbPassword >= 2 ? cbPassword - 2 : cbPassword;
if (!settings->RemoteAssistanceMode)
{
cbAlternateShell = ConvertToUnicode(CP_UTF8, 0, settings->AlternateShell, -1, &alternateShellW,
@ -821,6 +830,9 @@ static void rdp_write_info_packet(rdpRdp* rdp, wStream* s)
}
}
/* excludes (!) the length of the mandatory null terminator */
cbAlternateShell = cbAlternateShell >= 2 ? cbAlternateShell - 2 : cbAlternateShell;
if (!settings->RemoteAssistanceMode)
{
cbWorkingDir = ConvertToUnicode(CP_UTF8, 0, settings->ShellWorkingDirectory, -1, &workingDirW,
@ -833,6 +845,9 @@ static void rdp_write_info_packet(rdpRdp* rdp, wStream* s)
0) * 2;
}
/* excludes (!) the length of the mandatory null terminator */
cbWorkingDir = cbWorkingDir >= 2 ? cbWorkingDir - 2 : cbWorkingDir;
Stream_Write_UINT32(s, 0); /* CodePage (4 bytes) */
Stream_Write_UINT32(s, flags); /* flags (4 bytes) */
Stream_Write_UINT16(s, cbDomain); /* cbDomain (2 bytes) */
@ -844,27 +859,33 @@ static void rdp_write_info_packet(rdpRdp* rdp, wStream* s)
if (cbDomain > 0)
Stream_Write(s, domainW, cbDomain);
/* the mandatory null terminator */
Stream_Write_UINT16(s, 0);
if (cbUserName > 0)
Stream_Write(s, userNameW, cbUserName);
/* the mandatory null terminator */
Stream_Write_UINT16(s, 0);
if (cbPassword > 0)
Stream_Write(s, passwordW, cbPassword);
/* the mandatory null terminator */
Stream_Write_UINT16(s, 0);
if (cbAlternateShell > 0)
Stream_Write(s, alternateShellW, cbAlternateShell);
/* the mandatory null terminator */
Stream_Write_UINT16(s, 0);
if (cbWorkingDir > 0)
Stream_Write(s, workingDirW, cbWorkingDir);
/* the mandatory null terminator */
Stream_Write_UINT16(s, 0);
free(domainW);
free(userNameW);
free(alternateShellW);