advapi32: Don't use -1 as dstlen in MultiByteToWideChar.
This commit is contained in:
parent
224d33b2c9
commit
655478075f
|
@ -1010,40 +1010,54 @@ static INT convert_PCREDENTIALW_to_PCREDENTIALA(const CREDENTIALW *CredentialW,
|
||||||
return needed;
|
return needed;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void convert_PCREDENTIALA_to_PCREDENTIALW(const CREDENTIALA *CredentialA, PCREDENTIALW CredentialW, DWORD *len)
|
/******************************************************************************
|
||||||
|
* convert_PCREDENTIALA_to_PCREDENTIALW [internal]
|
||||||
|
*
|
||||||
|
* convert a Credential struct from ANSI to UNICODE and return the needed size in Bytes
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static INT convert_PCREDENTIALA_to_PCREDENTIALW(const CREDENTIALA *CredentialA, PCREDENTIALW CredentialW, INT len)
|
||||||
{
|
{
|
||||||
char *buffer = (char *)CredentialW + sizeof(CREDENTIALW);
|
char *buffer;
|
||||||
INT string_len;
|
INT string_len;
|
||||||
|
INT needed = sizeof(CREDENTIALW);
|
||||||
|
|
||||||
*len += sizeof(CREDENTIALW);
|
|
||||||
if (!CredentialW)
|
if (!CredentialW)
|
||||||
{
|
{
|
||||||
if (CredentialA->TargetName) *len += sizeof(WCHAR) * MultiByteToWideChar(CP_ACP, 0, CredentialA->TargetName, -1, NULL, 0);
|
if (CredentialA->TargetName)
|
||||||
if (CredentialA->Comment) *len += sizeof(WCHAR) * MultiByteToWideChar(CP_ACP, 0, CredentialA->Comment, -1, NULL, 0);
|
needed += sizeof(WCHAR) * MultiByteToWideChar(CP_ACP, 0, CredentialA->TargetName, -1, NULL, 0);
|
||||||
*len += CredentialA->CredentialBlobSize;
|
if (CredentialA->Comment)
|
||||||
if (CredentialA->TargetAlias) *len += sizeof(WCHAR) * MultiByteToWideChar(CP_ACP, 0, CredentialA->TargetAlias, -1, NULL, 0);
|
needed += sizeof(WCHAR) * MultiByteToWideChar(CP_ACP, 0, CredentialA->Comment, -1, NULL, 0);
|
||||||
if (CredentialA->UserName) *len += sizeof(WCHAR) * MultiByteToWideChar(CP_ACP, 0, CredentialA->UserName, -1, NULL, 0);
|
needed += CredentialA->CredentialBlobSize;
|
||||||
|
if (CredentialA->TargetAlias)
|
||||||
|
needed += sizeof(WCHAR) * MultiByteToWideChar(CP_ACP, 0, CredentialA->TargetAlias, -1, NULL, 0);
|
||||||
|
if (CredentialA->UserName)
|
||||||
|
needed += sizeof(WCHAR) * MultiByteToWideChar(CP_ACP, 0, CredentialA->UserName, -1, NULL, 0);
|
||||||
|
|
||||||
return;
|
return needed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buffer = (char *)CredentialW + sizeof(CREDENTIALW);
|
||||||
|
len -= sizeof(CREDENTIALW);
|
||||||
CredentialW->Flags = CredentialA->Flags;
|
CredentialW->Flags = CredentialA->Flags;
|
||||||
CredentialW->Type = CredentialA->Type;
|
CredentialW->Type = CredentialA->Type;
|
||||||
if (CredentialA->TargetName)
|
if (CredentialA->TargetName)
|
||||||
{
|
{
|
||||||
CredentialW->TargetName = (LPWSTR)buffer;
|
CredentialW->TargetName = (LPWSTR)buffer;
|
||||||
string_len = MultiByteToWideChar(CP_ACP, 0, CredentialA->TargetName, -1, CredentialW->TargetName, -1);
|
string_len = MultiByteToWideChar(CP_ACP, 0, CredentialA->TargetName, -1, CredentialW->TargetName, len / sizeof(WCHAR));
|
||||||
buffer += sizeof(WCHAR) * string_len;
|
buffer += sizeof(WCHAR) * string_len;
|
||||||
*len += sizeof(WCHAR) * string_len;
|
needed += sizeof(WCHAR) * string_len;
|
||||||
|
len -= sizeof(WCHAR) * string_len;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
CredentialW->TargetName = NULL;
|
CredentialW->TargetName = NULL;
|
||||||
if (CredentialA->Comment)
|
if (CredentialA->Comment)
|
||||||
{
|
{
|
||||||
CredentialW->Comment = (LPWSTR)buffer;
|
CredentialW->Comment = (LPWSTR)buffer;
|
||||||
string_len = MultiByteToWideChar(CP_ACP, 0, CredentialA->Comment, -1, CredentialW->Comment, -1);
|
string_len = MultiByteToWideChar(CP_ACP, 0, CredentialA->Comment, -1, CredentialW->Comment, len / sizeof(WCHAR));
|
||||||
buffer += sizeof(WCHAR) * string_len;
|
buffer += sizeof(WCHAR) * string_len;
|
||||||
*len += sizeof(WCHAR) * string_len;
|
needed += sizeof(WCHAR) * string_len;
|
||||||
|
len -= sizeof(WCHAR) * string_len;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
CredentialW->Comment = NULL;
|
CredentialW->Comment = NULL;
|
||||||
|
@ -1055,7 +1069,8 @@ static void convert_PCREDENTIALA_to_PCREDENTIALW(const CREDENTIALA *CredentialA,
|
||||||
memcpy(CredentialW->CredentialBlob, CredentialA->CredentialBlob,
|
memcpy(CredentialW->CredentialBlob, CredentialA->CredentialBlob,
|
||||||
CredentialA->CredentialBlobSize);
|
CredentialA->CredentialBlobSize);
|
||||||
buffer += CredentialA->CredentialBlobSize;
|
buffer += CredentialA->CredentialBlobSize;
|
||||||
*len += CredentialA->CredentialBlobSize;
|
needed += CredentialA->CredentialBlobSize;
|
||||||
|
len -= CredentialA->CredentialBlobSize;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
CredentialW->CredentialBlob = NULL;
|
CredentialW->CredentialBlob = NULL;
|
||||||
|
@ -1065,21 +1080,23 @@ static void convert_PCREDENTIALA_to_PCREDENTIALW(const CREDENTIALA *CredentialA,
|
||||||
if (CredentialA->TargetAlias)
|
if (CredentialA->TargetAlias)
|
||||||
{
|
{
|
||||||
CredentialW->TargetAlias = (LPWSTR)buffer;
|
CredentialW->TargetAlias = (LPWSTR)buffer;
|
||||||
string_len = MultiByteToWideChar(CP_ACP, 0, CredentialA->TargetAlias, -1, CredentialW->TargetAlias, -1);
|
string_len = MultiByteToWideChar(CP_ACP, 0, CredentialA->TargetAlias, -1, CredentialW->TargetAlias, len / sizeof(WCHAR));
|
||||||
buffer += sizeof(WCHAR) * string_len;
|
buffer += sizeof(WCHAR) * string_len;
|
||||||
*len += sizeof(WCHAR) * string_len;
|
needed += sizeof(WCHAR) * string_len;
|
||||||
|
len -= sizeof(WCHAR) * string_len;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
CredentialW->TargetAlias = NULL;
|
CredentialW->TargetAlias = NULL;
|
||||||
if (CredentialA->UserName)
|
if (CredentialA->UserName)
|
||||||
{
|
{
|
||||||
CredentialW->UserName = (LPWSTR)buffer;
|
CredentialW->UserName = (LPWSTR)buffer;
|
||||||
string_len = MultiByteToWideChar(CP_ACP, 0, CredentialA->UserName, -1, CredentialW->UserName, -1);
|
string_len = MultiByteToWideChar(CP_ACP, 0, CredentialA->UserName, -1, CredentialW->UserName, len / sizeof(WCHAR));
|
||||||
buffer += sizeof(WCHAR) * string_len;
|
needed += sizeof(WCHAR) * string_len;
|
||||||
*len += sizeof(WCHAR) * string_len;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
CredentialW->UserName = NULL;
|
CredentialW->UserName = NULL;
|
||||||
|
|
||||||
|
return needed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
|
@ -1730,7 +1747,7 @@ BOOL WINAPI CredReadDomainCredentialsW(PCREDENTIAL_TARGET_INFORMATIONW TargetInf
|
||||||
BOOL WINAPI CredWriteA(PCREDENTIALA Credential, DWORD Flags)
|
BOOL WINAPI CredWriteA(PCREDENTIALA Credential, DWORD Flags)
|
||||||
{
|
{
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
DWORD len;
|
INT len;
|
||||||
PCREDENTIALW CredentialW;
|
PCREDENTIALW CredentialW;
|
||||||
|
|
||||||
TRACE("(%p, 0x%x)\n", Credential, Flags);
|
TRACE("(%p, 0x%x)\n", Credential, Flags);
|
||||||
|
@ -1741,16 +1758,15 @@ BOOL WINAPI CredWriteA(PCREDENTIALA Credential, DWORD Flags)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = 0;
|
len = convert_PCREDENTIALA_to_PCREDENTIALW(Credential, NULL, 0);
|
||||||
convert_PCREDENTIALA_to_PCREDENTIALW(Credential, NULL, &len);
|
|
||||||
CredentialW = HeapAlloc(GetProcessHeap(), 0, len);
|
CredentialW = HeapAlloc(GetProcessHeap(), 0, len);
|
||||||
if (!CredentialW)
|
if (!CredentialW)
|
||||||
{
|
{
|
||||||
SetLastError(ERROR_OUTOFMEMORY);
|
SetLastError(ERROR_OUTOFMEMORY);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
len = 0;
|
|
||||||
convert_PCREDENTIALA_to_PCREDENTIALW(Credential, CredentialW, &len);
|
convert_PCREDENTIALA_to_PCREDENTIALW(Credential, CredentialW, len);
|
||||||
|
|
||||||
ret = CredWriteW(CredentialW, Flags);
|
ret = CredWriteW(CredentialW, Flags);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue