crypt32: Don't allocate a 0-length string.

This commit is contained in:
Juan Lang 2007-10-20 14:25:15 -07:00 committed by Alexandre Julliard
parent d34b3bf63c
commit e0b8e37bf0
1 changed files with 23 additions and 12 deletions

View File

@ -640,22 +640,33 @@ static BOOL CRYPT_EncodeValueWithType(DWORD dwCertEncodingType,
LPCWSTR *ppszError) LPCWSTR *ppszError)
{ {
CERT_NAME_VALUE nameValue = { type, { 0, NULL } }; CERT_NAME_VALUE nameValue = { type, { 0, NULL } };
BOOL ret = FALSE; BOOL ret = TRUE;
nameValue.Value.pbData = CryptMemAlloc((value->end - value->start) * if (value->end > value->start)
sizeof(WCHAR));
if (nameValue.Value.pbData)
{ {
DWORD i; nameValue.Value.pbData = CryptMemAlloc((value->end - value->start) *
LPWSTR ptr = (LPWSTR)nameValue.Value.pbData; sizeof(WCHAR));
if (!nameValue.Value.pbData)
for (i = 0; i < value->end - value->start; i++)
{ {
*ptr++ = value->start[i]; SetLastError(ERROR_OUTOFMEMORY);
if (value->start[i] == '"') ret = FALSE;
i++; }
}
if (ret)
{
if (value->end > value->start)
{
DWORD i;
LPWSTR ptr = (LPWSTR)nameValue.Value.pbData;
for (i = 0; i < value->end - value->start; i++)
{
*ptr++ = value->start[i];
if (value->start[i] == '"')
i++;
}
nameValue.Value.cbData = (LPBYTE)ptr - nameValue.Value.pbData;
} }
nameValue.Value.cbData = (LPBYTE)ptr - nameValue.Value.pbData;
ret = CryptEncodeObjectEx(dwCertEncodingType, X509_UNICODE_NAME_VALUE, ret = CryptEncodeObjectEx(dwCertEncodingType, X509_UNICODE_NAME_VALUE,
&nameValue, CRYPT_ENCODE_ALLOC_FLAG, NULL, &output->pbData, &nameValue, CRYPT_ENCODE_ALLOC_FLAG, NULL, &output->pbData,
&output->cbData); &output->cbData);