crypt32: Correct Unicode quoting of BMP strings.

This commit is contained in:
Juan Lang 2010-10-19 19:23:50 -07:00 committed by Alexandre Julliard
parent bf70d35529
commit 7833f30721
2 changed files with 44 additions and 11 deletions

View File

@ -73,12 +73,12 @@ DWORD WINAPI CertRDNValueToStrA(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue,
if (pValue->cbData && isspace(pValue->pbData[pValue->cbData - 1])) if (pValue->cbData && isspace(pValue->pbData[pValue->cbData - 1]))
needsQuotes = TRUE; needsQuotes = TRUE;
for (i = 0; i < pValue->cbData; i++) for (i = 0; i < pValue->cbData; i++)
{ {
if (is_quotable_char(pValue->pbData[i])) if (is_quotable_char(pValue->pbData[i]))
needsQuotes = TRUE; needsQuotes = TRUE;
if (pValue->pbData[i] == '"') if (pValue->pbData[i] == '"')
len += 1; len += 1;
} }
if (needsQuotes) if (needsQuotes)
len += 2; len += 2;
if (!psz || !csz) if (!psz || !csz)
@ -158,7 +158,7 @@ DWORD WINAPI CertRDNValueToStrA(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue,
DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue,
LPWSTR psz, DWORD csz) LPWSTR psz, DWORD csz)
{ {
DWORD ret = 0, len, i; DWORD ret = 0, len, i, strLen;
BOOL needsQuotes = FALSE; BOOL needsQuotes = FALSE;
TRACE("(%d, %p, %p, %d)\n", dwValueType, pValue, psz, csz); TRACE("(%d, %p, %p, %d)\n", dwValueType, pValue, psz, csz);
@ -175,19 +175,18 @@ DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue,
case CERT_RDN_GRAPHIC_STRING: case CERT_RDN_GRAPHIC_STRING:
case CERT_RDN_VISIBLE_STRING: case CERT_RDN_VISIBLE_STRING:
case CERT_RDN_GENERAL_STRING: case CERT_RDN_GENERAL_STRING:
case CERT_RDN_BMP_STRING:
len = pValue->cbData; len = pValue->cbData;
if (pValue->cbData && isspace(pValue->pbData[0])) if (pValue->cbData && isspace(pValue->pbData[0]))
needsQuotes = TRUE; needsQuotes = TRUE;
if (pValue->cbData && isspace(pValue->pbData[pValue->cbData - 1])) if (pValue->cbData && isspace(pValue->pbData[pValue->cbData - 1]))
needsQuotes = TRUE; needsQuotes = TRUE;
for (i = 0; i < pValue->cbData; i++) for (i = 0; i < pValue->cbData; i++)
{ {
if (is_quotable_char(pValue->pbData[i])) if (is_quotable_char(pValue->pbData[i]))
needsQuotes = TRUE; needsQuotes = TRUE;
if (pValue->pbData[i] == '"') if (pValue->pbData[i] == '"')
len += 1; len += 1;
} }
if (needsQuotes) if (needsQuotes)
len += 2; len += 2;
if (!psz || !csz) if (!psz || !csz)
@ -209,6 +208,40 @@ DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue,
ret = ptr - psz; ret = ptr - psz;
} }
break; break;
case CERT_RDN_BMP_STRING:
strLen = len = pValue->cbData / sizeof(WCHAR);
if (pValue->cbData && isspace(pValue->pbData[0]))
needsQuotes = TRUE;
if (pValue->cbData && isspace(pValue->pbData[strLen - 1]))
needsQuotes = TRUE;
for (i = 0; i < strLen; i++)
{
if (is_quotable_char(((LPCWSTR)pValue->pbData)[i]))
needsQuotes = TRUE;
if (((LPCWSTR)pValue->pbData)[i] == '"')
len += 1;
}
if (needsQuotes)
len += 2;
if (!psz || !csz)
ret = len;
else
{
WCHAR *ptr = psz;
if (needsQuotes)
*ptr++ = '"';
for (i = 0; i < strLen && ptr - psz < csz; ptr++, i++)
{
*ptr = ((LPCWSTR)pValue->pbData)[i];
if (((LPCWSTR)pValue->pbData)[i] == '"' && ptr - psz < csz - 1)
*(++ptr) = '"';
}
if (needsQuotes && ptr - psz < csz)
*ptr++ = '"';
ret = ptr - psz;
}
break;
default: default:
FIXME("string type %d unimplemented\n", dwValueType); FIXME("string type %d unimplemented\n", dwValueType);
} }

View File

@ -570,7 +570,7 @@ static void test_CertNameToStrW(void)
blob.pbData = encodedQuotedCN; blob.pbData = encodedQuotedCN;
blob.cbData = sizeof(encodedQuotedCN); blob.cbData = sizeof(encodedQuotedCN);
test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, quotedCN_W, test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, quotedCN_W,
TRUE); FALSE);
blob.pbData = encodedMultipleAttrCN; blob.pbData = encodedMultipleAttrCN;
blob.cbData = sizeof(encodedMultipleAttrCN); blob.cbData = sizeof(encodedMultipleAttrCN);
test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, multipleAttrCN_W, test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, multipleAttrCN_W,
@ -583,17 +583,17 @@ static void test_CertNameToStrW(void)
test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, equalCN_W, FALSE); test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, equalCN_W, FALSE);
blob.pbData = encodedLessThanCN; blob.pbData = encodedLessThanCN;
blob.cbData = sizeof(encodedLessThanCN); blob.cbData = sizeof(encodedLessThanCN);
test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, lessThanCN_W, TRUE); test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, lessThanCN_W, FALSE);
blob.pbData = encodedGreaterThanCN; blob.pbData = encodedGreaterThanCN;
blob.cbData = sizeof(encodedGreaterThanCN); blob.cbData = sizeof(encodedGreaterThanCN);
test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, greaterThanCN_W, test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, greaterThanCN_W,
TRUE); FALSE);
blob.pbData = encodedHashCN; blob.pbData = encodedHashCN;
blob.cbData = sizeof(encodedHashCN); blob.cbData = sizeof(encodedHashCN);
test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, hashCN_W, TRUE); test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, hashCN_W, FALSE);
blob.pbData = encodedSemiCN; blob.pbData = encodedSemiCN;
blob.cbData = sizeof(encodedSemiCN); blob.cbData = sizeof(encodedSemiCN);
test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, semiCN_W, TRUE); test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, semiCN_W, FALSE);
} }
struct StrToNameA struct StrToNameA