This is a resend of 233262-233269. Hans reviewed the previous version (https://www.winehq.org/pipermail/wine-devel/2022-April/214386.html) and I sent this one as the follow up with the only change fixing the compiler warning as test.
From: Paul Gofman pgofman@codeweavers.com
--- dlls/crypt32/tests/str.c | 331 +++++++++++++++------------------------ 1 file changed, 127 insertions(+), 204 deletions(-)
diff --git a/dlls/crypt32/tests/str.c b/dlls/crypt32/tests/str.c index a94381591c0..e10d5a4fb29 100644 --- a/dlls/crypt32/tests/str.c +++ b/dlls/crypt32/tests/str.c @@ -429,23 +429,31 @@ static void test_CertNameToStrA(void) test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, ""a\nb"", FALSE); }
-static void test_NameToStrConversionW(PCERT_NAME_BLOB pName, DWORD dwStrType, - LPCWSTR expected, BOOL todo) +#define test_NameToStrConversionW(a, b, c) test_NameToStrConversionW_(__LINE__, a, b, c) +static void test_NameToStrConversionW_(unsigned int line, PCERT_NAME_BLOB pName, DWORD dwStrType, LPCWSTR expected) { - WCHAR buffer[2000] = { 0 }; - DWORD i; + DWORD len, retlen, expected_len; + WCHAR buffer[2000];
- i = CertNameToStrW(X509_ASN_ENCODING,pName, dwStrType, NULL, 0); - todo_wine_if (todo) - ok(i == lstrlenW(expected) + 1, "Expected %d chars, got %ld\n", - lstrlenW(expected) + 1, i); - i = CertNameToStrW(X509_ASN_ENCODING,pName, dwStrType, buffer, ARRAY_SIZE(buffer)); - todo_wine_if (todo) - ok(i == lstrlenW(expected) + 1, "Expected %d chars, got %ld\n", - lstrlenW(expected) + 1, i); - todo_wine_if (todo) - ok(!lstrcmpW(buffer, expected), "Expected %s, got %s\n", - wine_dbgstr_w(expected), wine_dbgstr_w(buffer)); + expected_len = wcslen(expected) + 1; + memset(buffer, 0xcc, sizeof(buffer)); + len = CertNameToStrW(X509_ASN_ENCODING, pName, dwStrType, NULL, 0); + ok(len == expected_len, "line %u: expected %lu chars, got %lu\n", line, expected_len, len); + retlen = CertNameToStrW(X509_ASN_ENCODING, pName, dwStrType, buffer, ARRAY_SIZE(buffer)); + ok(retlen == len, "line %u: expected %lu chars, got %lu.\n", line, len, retlen); + ok(!wcscmp(buffer, expected), "Expected %s, got %s\n", wine_dbgstr_w(expected), wine_dbgstr_w(buffer)); + + memset(buffer, 0xcc, sizeof(buffer)); + retlen = CertNameToStrW(X509_ASN_ENCODING, pName, dwStrType, buffer, len - 1); + todo_wine ok(retlen == len - 1, "line %u: expected %lu chars, got %lu\n", line, len - 1, retlen); + ok(!wcsncmp(buffer, expected, retlen - 1), "line %u: expected %s, got %s\n", + line, wine_dbgstr_w(expected), wine_dbgstr_w(buffer)); + ok(!buffer[retlen - 1], "line %u: string is not zero terminated.\n", line); + + memset(buffer, 0xcc, sizeof(buffer)); + retlen = CertNameToStrW(X509_ASN_ENCODING, pName, dwStrType, buffer, 0); + todo_wine ok(retlen == len, "line %u: expected %lu chars, got %lu\n", line, len - 1, retlen); + ok(buffer[0] == 0xcccc, "line %u: got %s\n", line, wine_dbgstr_w(buffer)); }
static void test_CertNameToStrW(void) @@ -479,95 +487,79 @@ static void test_CertNameToStrW(void)
test_NameToStrConversionW(&context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR, - L"US, Minnesota, Minneapolis, CodeWeavers, Wine Development, localhost, aric@codeweavers.com", FALSE); + L"US, Minnesota, Minneapolis, CodeWeavers, Wine Development, localhost, aric@codeweavers.com"); test_NameToStrConversionW(&context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR | CERT_NAME_STR_SEMICOLON_FLAG, - L"US; Minnesota; Minneapolis; CodeWeavers; Wine Development; localhost; aric@codeweavers.com", FALSE); + L"US; Minnesota; Minneapolis; CodeWeavers; Wine Development; localhost; aric@codeweavers.com"); test_NameToStrConversionW(&context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR | CERT_NAME_STR_CRLF_FLAG, - L"US\r\nMinnesota\r\nMinneapolis\r\nCodeWeavers\r\nWine Development\r\nlocalhost\r\naric@codeweavers.com", - FALSE); + L"US\r\nMinnesota\r\nMinneapolis\r\nCodeWeavers\r\nWine Development\r\nlocalhost\r\naric@codeweavers.com"); test_NameToStrConversionW(&context->pCertInfo->Subject, CERT_OID_NAME_STR, L"2.5.4.6=US, 2.5.4.8=Minnesota, 2.5.4.7=Minneapolis, 2.5.4.10=CodeWeavers, 2.5.4.11=Wine Development," - " 2.5.4.3=localhost, 1.2.840.113549.1.9.1=aric@codeweavers.com", FALSE); + " 2.5.4.3=localhost, 1.2.840.113549.1.9.1=aric@codeweavers.com"); test_NameToStrConversionW(&context->pCertInfo->Subject, CERT_OID_NAME_STR | CERT_NAME_STR_SEMICOLON_FLAG, L"2.5.4.6=US; 2.5.4.8=Minnesota; 2.5.4.7=Minneapolis; 2.5.4.10=CodeWeavers; 2.5.4.11=Wine Development;" - " 2.5.4.3=localhost; 1.2.840.113549.1.9.1=aric@codeweavers.com", FALSE); + " 2.5.4.3=localhost; 1.2.840.113549.1.9.1=aric@codeweavers.com"); test_NameToStrConversionW(&context->pCertInfo->Subject, CERT_OID_NAME_STR | CERT_NAME_STR_CRLF_FLAG, L"2.5.4.6=US\r\n2.5.4.8=Minnesota\r\n2.5.4.7=Minneapolis\r\n2.5.4.10=CodeWeavers\r\n2.5.4.11=Wine " - "Development\r\n2.5.4.3=localhost\r\n1.2.840.113549.1.9.1=aric@codeweavers.com", FALSE); + "Development\r\n2.5.4.3=localhost\r\n1.2.840.113549.1.9.1=aric@codeweavers.com"); test_NameToStrConversionW(&context->pCertInfo->Subject, CERT_X500_NAME_STR | CERT_NAME_STR_SEMICOLON_FLAG | CERT_NAME_STR_REVERSE_FLAG, L"E=aric@codeweavers.com; CN=localhost; OU=Wine Development; O=CodeWeavers; L=Minneapolis; S=Minnesota; " - "C=US", FALSE); + "C=US");
CertFreeCertificateContext(context); } blob.pbData = encodedSimpleCN; blob.cbData = sizeof(encodedSimpleCN); - test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN=1", FALSE); + test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN=1"); blob.pbData = encodedSingleQuotedCN; blob.cbData = sizeof(encodedSingleQuotedCN); - test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN='1'", - FALSE); - test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, - L"'1'", FALSE); + test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN='1'"); + test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, L"'1'"); blob.pbData = encodedSpacedCN; blob.cbData = sizeof(encodedSpacedCN); - test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN=" 1 "", FALSE); - test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, L"" 1 "", - FALSE); + test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN=" 1 ""); + test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, L"" 1 ""); blob.pbData = encodedQuotedCN; blob.cbData = sizeof(encodedQuotedCN); - test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN="""1"""", - FALSE); - test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, L""""1"""", - FALSE); + test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN="""1""""); + test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, L""""1""""); blob.pbData = encodedMultipleAttrCN; blob.cbData = sizeof(encodedMultipleAttrCN); - test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN="1+2"", - FALSE); - test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, - L""1+2"", FALSE); + test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN="1+2""); + test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, L""1+2""); blob.pbData = encodedCommaCN; blob.cbData = sizeof(encodedCommaCN); - test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN="a,b"", FALSE); - test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, L""a,b"", - FALSE); + test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN="a,b""); + test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, L""a,b""); blob.pbData = encodedEqualCN; blob.cbData = sizeof(encodedEqualCN); - test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN="a=b"", FALSE); - test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, L""a=b"", - FALSE); + test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN="a=b""); + test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, L""a=b""); blob.pbData = encodedLessThanCN; blob.cbData = sizeof(encodedLessThanCN); - test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN="<"", FALSE); - test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, L""<"", - FALSE); + test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN="<""); + test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, L""<""); blob.pbData = encodedGreaterThanCN; blob.cbData = sizeof(encodedGreaterThanCN); - test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN=">"", - FALSE); - test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, - L"">"", FALSE); + test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN=">""); + test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, L"">""); blob.pbData = encodedHashCN; blob.cbData = sizeof(encodedHashCN); - test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN="#"", FALSE); - test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, L""#"", - FALSE); + test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN="#""); + test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, L""#""); blob.pbData = encodedSemiCN; blob.cbData = sizeof(encodedSemiCN); - test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN=";"", FALSE); - test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, L"";"", - FALSE); + test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN=";""); + test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, L"";""); blob.pbData = encodedNewlineCN; blob.cbData = sizeof(encodedNewlineCN); - test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN="a\nb"", FALSE); - test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, L""a\nb"", - FALSE); + test_NameToStrConversionW(&blob, CERT_X500_NAME_STR, L"CN="a\nb""); + test_NameToStrConversionW(&blob, CERT_SIMPLE_NAME_STR, L""a\nb""); }
struct StrToNameA @@ -747,153 +739,84 @@ static void test_CertStrToNameW(void) } }
-static void test_CertGetNameStringA(void) +#define test_CertGetNameString_value(a, b, c, d) test_CertGetNameString_value_(__LINE__, a, b, c, d) +static void test_CertGetNameString_value_(unsigned int line, PCCERT_CONTEXT context, DWORD type, void *type_para, + const char *expected) +{ + WCHAR expectedW[512]; + DWORD len, retlen; + WCHAR strW[512]; + unsigned int i; + char str[512]; + + for (i = 0; expected[i]; ++i) + expectedW[i] = expected[i]; + expectedW[i] = 0; + + len = CertGetNameStringA(context, type, 0, type_para, NULL, 0); + ok(len == strlen(expected) + 1, "line %u: unexpected length %ld.\n", line, len); + retlen = CertGetNameStringA(context, type, 0, type_para, str, len); + ok(retlen == len, "line %u: unexpected len %lu, expected %lu.\n", line, retlen, len); + ok(!strcmp(str, expected), "line %u: unexpected value %s.\n", line, str); + str[0] = str[1] = 0xcc; + retlen = CertGetNameStringA(context, type, 0, type_para, str, len - 1); + todo_wine ok(retlen == 1, "line %u: Unexpected len %lu, expected 1.\n", line, retlen); + todo_wine ok(!str[0], "line %u: unexpected str[0] %#x.\n", line, str[0]); + ok(str[1] == expected[1], "line %u: unexpected str[1] %#x.\n", line, str[1]); + retlen = CertGetNameStringW(context, type, 0, type_para, strW, len); + ok(retlen == len, "line %u: unexpected len %lu, expected 1.\n", line, retlen); + ok(!wcscmp(strW, expectedW), "line %u: unexpected value %s.\n", line, debugstr_w(strW)); + strW[0] = strW[1] = 0xcccc; + retlen = CertGetNameStringW(context, type, 0, type_para, strW, len - 1); + todo_wine ok(retlen == len - 1, "line %u: unexpected len %lu, expected %lu.\n", line, retlen, len - 1); + ok(!wcsncmp(strW, expectedW, retlen - 1), "line %u: string data mismatch.\n", line); + ok(!strW[retlen - 1], "line %u: string is not zero terminated.\n", line); + retlen = CertGetNameStringA(context, type, 0, type_para, NULL, len - 1); + ok(retlen == len, "line %u: unexpected len %lu, expected %lu\n", line, retlen, len); + retlen = CertGetNameStringW(context, type, 0, type_para, NULL, len - 1); + ok(retlen == len, "line %u: unexpected len %lu, expected %lu\n", line, retlen, len); +} + +static void test_CertGetNameString(void) { + static const char aric[] = "aric@codeweavers.com"; + static const char localhost[] = "localhost"; PCCERT_CONTEXT context; + DWORD len, type;
context = CertCreateCertificateContext(X509_ASN_ENCODING, cert, sizeof(cert)); - ok(context != NULL, "CertCreateCertificateContext failed: %08lx\n", - GetLastError()); - if (context) - { - static const char aric[] = "aric@codeweavers.com"; - static const char localhost[] = "localhost"; - DWORD len, type; - LPSTR str; - - /* Bad string types/types missing from the cert */ - len = CertGetNameStringA(NULL, 0, 0, NULL, NULL, 0); - ok(len == 1, "expected 1, got %ld\n", len); - len = CertGetNameStringA(context, 0, 0, NULL, NULL, 0); - ok(len == 1, "expected 1, got %ld\n", len); - len = CertGetNameStringA(context, CERT_NAME_URL_TYPE, 0, NULL, NULL, - 0); - ok(len == 1, "expected 1, got %ld\n", len); - - len = CertGetNameStringA(context, CERT_NAME_EMAIL_TYPE, 0, NULL, NULL, - 0); - ok(len == strlen(aric) + 1, "unexpected length %ld\n", len); - str = HeapAlloc(GetProcessHeap(), 0, len); - if (str) - { - len = CertGetNameStringA(context, CERT_NAME_EMAIL_TYPE, 0, NULL, - str, len); - ok(!strcmp(str, aric), "unexpected value %s\n", str); - HeapFree(GetProcessHeap(), 0, str); - } - - len = CertGetNameStringA(context, CERT_NAME_RDN_TYPE, 0, NULL, NULL, - 0); - ok(len == strlen(issuerStr) + 1, "unexpected length %ld\n", len); - str = HeapAlloc(GetProcessHeap(), 0, len); - if (str) - { - len = CertGetNameStringA(context, CERT_NAME_RDN_TYPE, 0, NULL, - str, len); - ok(!strcmp(str, issuerStr), "unexpected value %s\n", str); - HeapFree(GetProcessHeap(), 0, str); - } - type = 0; - len = CertGetNameStringA(context, CERT_NAME_RDN_TYPE, 0, &type, NULL, - 0); - ok(len == strlen(issuerStr) + 1, "unexpected length %ld\n", len); - str = HeapAlloc(GetProcessHeap(), 0, len); - if (str) - { - len = CertGetNameStringA(context, CERT_NAME_RDN_TYPE, 0, &type, - str, len); - ok(!strcmp(str, issuerStr), "unexpected value %s\n", str); - HeapFree(GetProcessHeap(), 0, str); - } - type = CERT_OID_NAME_STR; - len = CertGetNameStringA(context, CERT_NAME_RDN_TYPE, 0, &type, NULL, - 0); - ok(len == strlen(subjectStr) + 1, "unexpected length %ld\n", len); - str = HeapAlloc(GetProcessHeap(), 0, len); - if (str) - { - len = CertGetNameStringA(context, CERT_NAME_RDN_TYPE, 0, &type, - str, len); - ok(!strcmp(str, subjectStr), "unexpected value %s\n", str); - HeapFree(GetProcessHeap(), 0, str); - } - - len = CertGetNameStringA(context, CERT_NAME_ATTR_TYPE, 0, NULL, NULL, - 0); - ok(len == strlen(aric) + 1, "unexpected length %ld\n", len); - str = HeapAlloc(GetProcessHeap(), 0, len); - if (str) - { - len = CertGetNameStringA(context, CERT_NAME_ATTR_TYPE, 0, NULL, - str, len); - ok(!strcmp(str, aric), "unexpected value %s\n", str); - HeapFree(GetProcessHeap(), 0, str); - } - len = CertGetNameStringA(context, CERT_NAME_ATTR_TYPE, 0, - (void *)szOID_RSA_emailAddr, NULL, 0); - ok(len == strlen(aric) + 1, "unexpected length %ld\n", len); - str = HeapAlloc(GetProcessHeap(), 0, len); - if (str) - { - len = CertGetNameStringA(context, CERT_NAME_ATTR_TYPE, 0, - (void *)szOID_RSA_emailAddr, str, len); - ok(!strcmp(str, aric), "unexpected value %s\n", str); - HeapFree(GetProcessHeap(), 0, str); - } - len = CertGetNameStringA(context, CERT_NAME_ATTR_TYPE, 0, - (void *)szOID_COMMON_NAME, NULL, 0); - ok(len == strlen(localhost) + 1, "unexpected length %ld\n", len); - str = HeapAlloc(GetProcessHeap(), 0, len); - if (str) - { - len = CertGetNameStringA(context, CERT_NAME_ATTR_TYPE, 0, - (void *)szOID_COMMON_NAME, str, len); - ok(!strcmp(str, localhost), "unexpected value %s\n", str); - HeapFree(GetProcessHeap(), 0, str); - } - - len = CertGetNameStringA(context, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, - NULL, NULL, 0); - ok(len == strlen(localhost) + 1, "unexpected length %ld\n", len); - str = HeapAlloc(GetProcessHeap(), 0, len); - if (str) - { - len = CertGetNameStringA(context, CERT_NAME_SIMPLE_DISPLAY_TYPE, - 0, NULL, str, len); - ok(!strcmp(str, localhost), "unexpected value %s\n", str); - HeapFree(GetProcessHeap(), 0, str); - } - - len = CertGetNameStringA(context, CERT_NAME_FRIENDLY_DISPLAY_TYPE, 0, - NULL, NULL, 0); - ok(len == strlen(localhost) + 1, "unexpected length %ld\n", len); - str = HeapAlloc(GetProcessHeap(), 0, len); - if (str) - { - len = CertGetNameStringA(context, CERT_NAME_FRIENDLY_DISPLAY_TYPE, - 0, NULL, str, len); - ok(!strcmp(str, localhost), "unexpected value %s\n", str); - HeapFree(GetProcessHeap(), 0, str); - } - - len = CertGetNameStringA(context, CERT_NAME_DNS_TYPE, 0, NULL, NULL, - 0); - ok(len == strlen(localhost) + 1, "unexpected length %ld\n", len); - if (len > 1) - { - str = HeapAlloc(GetProcessHeap(), 0, len); - if (str) - { - len = CertGetNameStringA(context, CERT_NAME_DNS_TYPE, 0, NULL, - str, len); - ok(!strcmp(str, localhost), "unexpected value %s\n", str); - HeapFree(GetProcessHeap(), 0, str); - } - } - - CertFreeCertificateContext(context); - } + ok(!!context, "CertCreateCertificateContext failed, err %lu\n", GetLastError()); + + /* Bad string types/types missing from the cert */ + len = CertGetNameStringA(NULL, 0, 0, NULL, NULL, 0); + ok(len == 1, "expected 1, got %lu\n", len); + len = CertGetNameStringA(context, 0, 0, NULL, NULL, 0); + ok(len == 1, "expected 1, got %lu\n", len); + len = CertGetNameStringA(context, CERT_NAME_URL_TYPE, 0, NULL, NULL, 0); + ok(len == 1, "expected 1, got %lu\n", len); + + len = CertGetNameStringW(NULL, 0, 0, NULL, NULL, 0); + ok(len == 1, "expected 1, got %lu\n", len); + len = CertGetNameStringW(context, 0, 0, NULL, NULL, 0); + ok(len == 1, "expected 1, got %lu\n", len); + len = CertGetNameStringW(context, CERT_NAME_URL_TYPE, 0, NULL, NULL, 0); + ok(len == 1, "expected 1, got %lu\n", len); + + test_CertGetNameString_value(context, CERT_NAME_EMAIL_TYPE, NULL, aric); + test_CertGetNameString_value(context, CERT_NAME_RDN_TYPE, NULL, issuerStr); + type = 0; + test_CertGetNameString_value(context, CERT_NAME_RDN_TYPE, &type, issuerStr); + type = CERT_OID_NAME_STR; + test_CertGetNameString_value(context, CERT_NAME_RDN_TYPE, &type, subjectStr); + test_CertGetNameString_value(context, CERT_NAME_ATTR_TYPE, NULL, aric); + test_CertGetNameString_value(context, CERT_NAME_ATTR_TYPE, (void *)szOID_RSA_emailAddr, aric); + test_CertGetNameString_value(context, CERT_NAME_ATTR_TYPE, (void *)szOID_COMMON_NAME, localhost); + test_CertGetNameString_value(context, CERT_NAME_SIMPLE_DISPLAY_TYPE, NULL, localhost); + test_CertGetNameString_value(context, CERT_NAME_FRIENDLY_DISPLAY_TYPE, NULL, localhost); + test_CertGetNameString_value(context, CERT_NAME_DNS_TYPE, NULL, localhost); + + CertFreeCertificateContext(context); }
START_TEST(str) @@ -904,5 +827,5 @@ START_TEST(str) test_CertNameToStrW(); test_CertStrToNameA(); test_CertStrToNameW(); - test_CertGetNameStringA(); + test_CertGetNameString(); }
From: Paul Gofman pgofman@codeweavers.com
--- dlls/crypt32/str.c | 61 ++++++++++++++++++++-------------------- dlls/crypt32/tests/str.c | 7 +++-- 2 files changed, 34 insertions(+), 34 deletions(-)
diff --git a/dlls/crypt32/str.c b/dlls/crypt32/str.c index 277aeb70d4a..8a1684f07ad 100644 --- a/dlls/crypt32/str.c +++ b/dlls/crypt32/str.c @@ -375,14 +375,6 @@ static DWORD quote_rdn_value_to_str_w(DWORD dwValueType, default: FIXME("string type %ld unimplemented\n", dwValueType); } - if (psz && csz) - { - *(psz + ret) = '\0'; - csz--; - ret++; - } - else - ret++; TRACE("returning %ld (%s)\n", ret, debugstr_w(psz)); return ret; } @@ -580,6 +572,7 @@ DWORD cert_name_to_str_with_indent(DWORD dwCertEncodingType, DWORD indentLevel, DWORD ret = 0, bytes = 0; BOOL bRet; CERT_NAME_INFO *info; + DWORD chars;
if (dwStrType & unsupportedFlags) FIXME("unsupported flags: %08lx\n", dwStrType & unsupportedFlags); @@ -607,14 +600,17 @@ DWORD cert_name_to_str_with_indent(DWORD dwCertEncodingType, DWORD indentLevel, else rdnSep = L" + "; rdnSepLen = lstrlenW(rdnSep); - for (i = 0; (!psz || ret < csz) && i < info->cRDN; i++) + if (!csz) psz = NULL; + for (i = 0; i < info->cRDN; i++) { - for (j = 0; (!psz || ret < csz) && j < rdn->cRDNAttr; j++) + if (psz && ret + 1 == csz) break; + for (j = 0; j < rdn->cRDNAttr; j++) { - DWORD chars; LPCSTR prefixA = NULL; LPCWSTR prefixW = NULL;
+ if (psz && ret + 1 == csz) break; + if ((dwStrType & 0x000000ff) == CERT_OID_NAME_STR) prefixA = rdn->rgRDNAttr[j].pszObjId; else if ((dwStrType & 0x000000ff) == CERT_X500_NAME_STR) @@ -644,6 +640,7 @@ DWORD cert_name_to_str_with_indent(DWORD dwCertEncodingType, DWORD indentLevel, chars = lstrlenW(indent); ret += chars; } + if (psz && ret + 1 == csz) break; } if (prefixW) { @@ -659,38 +656,40 @@ DWORD cert_name_to_str_with_indent(DWORD dwCertEncodingType, DWORD indentLevel, psz ? psz + ret : NULL, psz ? csz - ret - 1 : 0); ret += chars; } - chars = quote_rdn_value_to_str_w( - rdn->rgRDNAttr[j].dwValueType, - &rdn->rgRDNAttr[j].Value, psz ? psz + ret : NULL, - psz ? csz - ret : 0); - if (chars) - ret += chars - 1; + if (psz && ret + 1 == csz) break; + + chars = quote_rdn_value_to_str_w(rdn->rgRDNAttr[j].dwValueType, &rdn->rgRDNAttr[j].Value, + psz ? psz + ret : NULL, psz ? csz - ret - 1 : 0); + ret += chars; if (j < rdn->cRDNAttr - 1) { - if (psz && ret < csz - rdnSepLen - 1) - memcpy(psz + ret, rdnSep, rdnSepLen * sizeof(WCHAR)); - ret += rdnSepLen; + if (psz) + { + chars = min(rdnSepLen, csz - ret - 1); + memcpy(psz + ret, rdnSep, chars * sizeof(WCHAR)); + ret += chars; + } + else ret += rdnSepLen; } } + if (psz && ret + 1 == csz) break; if (i < info->cRDN - 1) { - if (psz && ret < csz - sepLen - 1) - memcpy(psz + ret, sep, sepLen * sizeof(WCHAR)); - ret += sepLen; + if (psz) + { + chars = min(sepLen, csz - ret - 1); + memcpy(psz + ret, sep, chars * sizeof(WCHAR)); + ret += chars; + } + else ret += sepLen; } if(reverse) rdn--; else rdn++; } LocalFree(info); } - if (psz && csz) - { - *(psz + ret) = '\0'; - ret++; - } - else - ret++; - return ret; + if (psz && csz) psz[ret] = 0; + return ret + 1; }
DWORD WINAPI CertNameToStrW(DWORD dwCertEncodingType, PCERT_NAME_BLOB pName, diff --git a/dlls/crypt32/tests/str.c b/dlls/crypt32/tests/str.c index e10d5a4fb29..f2ee5b96853 100644 --- a/dlls/crypt32/tests/str.c +++ b/dlls/crypt32/tests/str.c @@ -445,14 +445,14 @@ static void test_NameToStrConversionW_(unsigned int line, PCERT_NAME_BLOB pName,
memset(buffer, 0xcc, sizeof(buffer)); retlen = CertNameToStrW(X509_ASN_ENCODING, pName, dwStrType, buffer, len - 1); - todo_wine ok(retlen == len - 1, "line %u: expected %lu chars, got %lu\n", line, len - 1, retlen); + ok(retlen == len - 1, "line %u: expected %lu chars, got %lu\n", line, len - 1, retlen); ok(!wcsncmp(buffer, expected, retlen - 1), "line %u: expected %s, got %s\n", line, wine_dbgstr_w(expected), wine_dbgstr_w(buffer)); ok(!buffer[retlen - 1], "line %u: string is not zero terminated.\n", line);
memset(buffer, 0xcc, sizeof(buffer)); retlen = CertNameToStrW(X509_ASN_ENCODING, pName, dwStrType, buffer, 0); - todo_wine ok(retlen == len, "line %u: expected %lu chars, got %lu\n", line, len - 1, retlen); + ok(retlen == len, "line %u: expected %lu chars, got %lu\n", line, len - 1, retlen); ok(buffer[0] == 0xcccc, "line %u: got %s\n", line, wine_dbgstr_w(buffer)); }
@@ -768,7 +768,8 @@ static void test_CertGetNameString_value_(unsigned int line, PCCERT_CONTEXT cont ok(!wcscmp(strW, expectedW), "line %u: unexpected value %s.\n", line, debugstr_w(strW)); strW[0] = strW[1] = 0xcccc; retlen = CertGetNameStringW(context, type, 0, type_para, strW, len - 1); - todo_wine ok(retlen == len - 1, "line %u: unexpected len %lu, expected %lu.\n", line, retlen, len - 1); + todo_wine_if(type != CERT_NAME_RDN_TYPE) + ok(retlen == len - 1, "line %u: unexpected len %lu, expected %lu.\n", line, retlen, len - 1); ok(!wcsncmp(strW, expectedW, retlen - 1), "line %u: string data mismatch.\n", line); ok(!strW[retlen - 1], "line %u: string is not zero terminated.\n", line); retlen = CertGetNameStringA(context, type, 0, type_para, NULL, len - 1);
From: Paul Gofman pgofman@codeweavers.com
--- dlls/crypt32/str.c | 38 +++++++++++------------------ dlls/crypt32/tests/str.c | 52 ++++++++++++++++++++++------------------ 2 files changed, 43 insertions(+), 47 deletions(-)
diff --git a/dlls/crypt32/str.c b/dlls/crypt32/str.c index 8a1684f07ad..732dcb5ae33 100644 --- a/dlls/crypt32/str.c +++ b/dlls/crypt32/str.c @@ -99,7 +99,7 @@ DWORD WINAPI CertRDNValueToStrA(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, LPWSTR psz, DWORD csz) { - DWORD ret = 0, len, i, strLen; + DWORD ret = 0, len, i;
TRACE("(%ld, %p, %p, %ld)\n", dwValueType, pValue, psz, csz);
@@ -116,44 +116,34 @@ DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, case CERT_RDN_VISIBLE_STRING: case CERT_RDN_GENERAL_STRING: len = pValue->cbData; - if (!psz || !csz) - ret = len; - else + if (!psz || !csz) ret = len; + else if (len < csz) { - WCHAR *ptr = psz; - - for (i = 0; i < pValue->cbData && ptr - psz < csz; ptr++, i++) - *ptr = pValue->pbData[i]; - ret = ptr - psz; + for (i = 0; i < len; ++i) + psz[i] = pValue->pbData[i]; + ret = len; } break; case CERT_RDN_BMP_STRING: case CERT_RDN_UTF8_STRING: - strLen = len = pValue->cbData / sizeof(WCHAR); + len = pValue->cbData / sizeof(WCHAR); if (!psz || !csz) ret = len; - else + else if (len < csz) { WCHAR *ptr = psz;
- for (i = 0; i < strLen && ptr - psz < csz; ptr++, i++) - *ptr = ((LPCWSTR)pValue->pbData)[i]; - ret = ptr - psz; + for (i = 0; i < len; ++i) + ptr[i] = ((LPCWSTR)pValue->pbData)[i]; + ret = len; } break; default: FIXME("string type %ld unimplemented\n", dwValueType); } - if (psz && csz) - { - *(psz + ret) = '\0'; - csz--; - ret++; - } - else - ret++; - TRACE("returning %ld (%s)\n", ret, debugstr_w(psz)); - return ret; + if (psz && csz) psz[ret] = 0; + TRACE("returning %ld (%s)\n", ret + 1, debugstr_w(psz)); + return ret + 1; }
static inline BOOL is_quotable_char(WCHAR c) diff --git a/dlls/crypt32/tests/str.c b/dlls/crypt32/tests/str.c index f2ee5b96853..62889242e94 100644 --- a/dlls/crypt32/tests/str.c +++ b/dlls/crypt32/tests/str.c @@ -39,7 +39,6 @@ typedef struct _CertRDNAttrEncodingW { DWORD dwValueType; CERT_RDN_VALUE_BLOB Value; LPCWSTR str; - BOOL todo; } CertRDNAttrEncodingW, *PCertRDNAttrEncodingW;
static BYTE bin1[] = { 0x55, 0x53 }; @@ -202,33 +201,34 @@ static void test_CertRDNValueToStrW(void) static const WCHAR ePKIW[] = L"ePKI Root Certification Authority"; CertRDNAttrEncodingW attrs[] = { { "2.5.4.6", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin1), bin1 }, L"US", FALSE }, + { sizeof(bin1), bin1 }, L"US" }, { "2.5.4.8", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin2), bin2 }, L"Minnesota", FALSE }, + { sizeof(bin2), bin2 }, L"Minnesota" }, { "2.5.4.7", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin3), bin3 }, L"Minneapolis", FALSE }, + { sizeof(bin3), bin3 }, L"Minneapolis" }, { "2.5.4.10", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin4), bin4 }, L"CodeWeavers", FALSE }, + { sizeof(bin4), bin4 }, L"CodeWeavers" }, { "2.5.4.11", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin5), bin5 }, L"Wine Development", FALSE }, + { sizeof(bin5), bin5 }, L"Wine Development" }, { "2.5.4.3", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin6), bin6 }, L"localhost", FALSE }, + { sizeof(bin6), bin6 }, L"localhost" }, { "1.2.840.113549.1.9.1", CERT_RDN_IA5_STRING, - { sizeof(bin7), bin7 }, L"aric@codeweavers.com", FALSE }, + { sizeof(bin7), bin7 }, L"aric@codeweavers.com" }, { "0", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin9), bin9 }, L"abc"def", FALSE }, + { sizeof(bin9), bin9 }, L"abc"def" }, { "0", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin10), bin10 }, L"abc'def", FALSE }, + { sizeof(bin10), bin10 }, L"abc'def" }, { "0", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin11), bin11 }, L"abc, def", FALSE }, + { sizeof(bin11), bin11 }, L"abc, def" }, { "0", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin12), bin12 }, L" abc ", FALSE }, + { sizeof(bin12), bin12 }, L" abc " }, { "0", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin13), bin13 }, L""def"", FALSE }, + { sizeof(bin13), bin13 }, L""def"" }, { "0", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin14), bin14 }, L"1;3", FALSE }, + { sizeof(bin14), bin14 }, L"1;3" }, }; - DWORD i, ret; + unsigned int i; + DWORD ret, len; WCHAR buffer[2000]; CERT_RDN_VALUE_BLOB blob = { 0, NULL };
@@ -245,14 +245,20 @@ static void test_CertRDNValueToStrW(void)
for (i = 0; i < ARRAY_SIZE(attrs); i++) { - ret = CertRDNValueToStrW(attrs[i].dwValueType, &attrs[i].Value, buffer, ARRAY_SIZE(buffer)); - todo_wine_if (attrs[i].todo) - { - ok(ret == lstrlenW(attrs[i].str) + 1, - "Expected length %d, got %ld\n", lstrlenW(attrs[i].str) + 1, ret); - ok(!lstrcmpW(buffer, attrs[i].str), "Expected %s, got %s\n", - wine_dbgstr_w(attrs[i].str), wine_dbgstr_w(buffer)); - } + len = CertRDNValueToStrW(attrs[i].dwValueType, &attrs[i].Value, buffer, ARRAY_SIZE(buffer)); + ok(len == lstrlenW(attrs[i].str) + 1, + "Expected length %d, got %ld\n", lstrlenW(attrs[i].str) + 1, ret); + ok(!lstrcmpW(buffer, attrs[i].str), "Expected %s, got %s\n", + wine_dbgstr_w(attrs[i].str), wine_dbgstr_w(buffer)); + memset(buffer, 0xcc, sizeof(buffer)); + ret = CertRDNValueToStrW(attrs[i].dwValueType, &attrs[i].Value, buffer, len - 1); + ok(ret == 1, "Unexpected ret %lu, expected 1, test %u.\n", ret, i); + ok(!buffer[0], "Unexpected value %#x, test %u.\n", buffer[0], i); + ok(buffer[1] == 0xcccc, "Unexpected value %#x, test %u.\n", buffer[1], i); + memset(buffer, 0xcc, sizeof(buffer)); + ret = CertRDNValueToStrW(attrs[i].dwValueType, &attrs[i].Value, buffer, 0); + ok(ret == len, "Unexpected ret %lu, expected %lu, test %u.\n", ret, len, i); + ok(buffer[0] == 0xcccc, "Unexpected value %#x, test %u.\n", buffer[0], i); } blob.pbData = bin8; blob.cbData = sizeof(bin8);
From: Paul Gofman pgofman@codeweavers.com
--- dlls/crypt32/str.c | 100 +++++++++++++++------------------------ dlls/crypt32/tests/str.c | 3 +- 2 files changed, 39 insertions(+), 64 deletions(-)
diff --git a/dlls/crypt32/str.c b/dlls/crypt32/str.c index 732dcb5ae33..ad0c71d697f 100644 --- a/dlls/crypt32/str.c +++ b/dlls/crypt32/str.c @@ -96,8 +96,8 @@ DWORD WINAPI CertRDNValueToStrA(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, return ret; }
-DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, - LPWSTR psz, DWORD csz) +static DWORD rdn_value_to_strW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, + LPWSTR psz, DWORD csz, BOOL partial_copy) { DWORD ret = 0, len, i;
@@ -117,8 +117,9 @@ DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, case CERT_RDN_GENERAL_STRING: len = pValue->cbData; if (!psz || !csz) ret = len; - else if (len < csz) + else if (len < csz || partial_copy) { + len = min(len, csz - 1); for (i = 0; i < len; ++i) psz[i] = pValue->pbData[i]; ret = len; @@ -129,10 +130,11 @@ DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, len = pValue->cbData / sizeof(WCHAR); if (!psz || !csz) ret = len; - else if (len < csz) + else if (len < csz || partial_copy) { WCHAR *ptr = psz;
+ len = min(len, csz - 1); for (i = 0; i < len; ++i) ptr[i] = ((LPCWSTR)pValue->pbData)[i]; ret = len; @@ -146,6 +148,12 @@ DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, return ret + 1; }
+DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, + LPWSTR psz, DWORD csz) +{ + return rdn_value_to_strW(dwValueType, pValue, psz, csz, FALSE); +} + static inline BOOL is_quotable_char(WCHAR c) { switch(c) @@ -1196,13 +1204,24 @@ static DWORD cert_get_name_from_rdn_attr(DWORD encodingType, oid = szOID_RSA_emailAddr; nameAttr = CertFindRDNAttr(oid, nameInfo); if (nameAttr) - ret = CertRDNValueToStrW(nameAttr->dwValueType, &nameAttr->Value, - pszNameString, cchNameString); + ret = rdn_value_to_strW(nameAttr->dwValueType, &nameAttr->Value, + pszNameString, cchNameString, TRUE); LocalFree(nameInfo); } return ret; }
+static DWORD copy_output_str(WCHAR *dst, const WCHAR *src, DWORD dst_size) +{ + DWORD len = wcslen(src); + + if (!dst || !dst_size) return len + 1; + len = min(len, dst_size - 1); + memcpy(dst, src, len * sizeof(*dst)); + dst[len] = 0; + return len + 1; +} + DWORD WINAPI CertGetNameStringW(PCCERT_CONTEXT pCertContext, DWORD dwType, DWORD dwFlags, void *pvTypePara, LPWSTR pszNameString, DWORD cchNameString) { @@ -1235,23 +1254,14 @@ DWORD WINAPI CertGetNameStringW(PCCERT_CONTEXT pCertContext, DWORD dwType, PCERT_ALT_NAME_ENTRY entry = cert_find_alt_name_entry(pCertContext, altNameOID, CERT_ALT_NAME_RFC822_NAME, &info);
- if (entry) - { - if (!pszNameString) - ret = lstrlenW(entry->u.pwszRfc822Name) + 1; - else if (cchNameString) - { - ret = min(lstrlenW(entry->u.pwszRfc822Name), cchNameString - 1); - memcpy(pszNameString, entry->u.pwszRfc822Name, - ret * sizeof(WCHAR)); - pszNameString[ret++] = 0; - } - } + if (entry) ret = copy_output_str(pszNameString, entry->u.pwszRfc822Name, cchNameString); if (info) LocalFree(info); if (!ret) + { ret = cert_get_name_from_rdn_attr(pCertContext->dwCertEncodingType, name, szOID_RSA_emailAddr, pszNameString, cchNameString); + } break; } case CERT_NAME_RDN_TYPE: @@ -1308,8 +1318,8 @@ DWORD WINAPI CertGetNameStringW(PCCERT_CONTEXT pCertContext, DWORD dwType, for (i = 0; !nameAttr && i < ARRAY_SIZE(simpleAttributeOIDs); i++) nameAttr = CertFindRDNAttr(simpleAttributeOIDs[i], nameInfo); if (nameAttr) - ret = CertRDNValueToStrW(nameAttr->dwValueType, - &nameAttr->Value, pszNameString, cchNameString); + ret = rdn_value_to_strW(nameAttr->dwValueType, + &nameAttr->Value, pszNameString, cchNameString, TRUE); LocalFree(nameInfo); } if (!ret) @@ -1322,19 +1332,7 @@ DWORD WINAPI CertGetNameStringW(PCCERT_CONTEXT pCertContext, DWORD dwType, { if (!entry && altInfo->cAltEntry) entry = &altInfo->rgAltEntry[0]; - if (entry) - { - if (!pszNameString) - ret = lstrlenW(entry->u.pwszRfc822Name) + 1; - else if (cchNameString) - { - ret = min(lstrlenW(entry->u.pwszRfc822Name), - cchNameString - 1); - memcpy(pszNameString, entry->u.pwszRfc822Name, - ret * sizeof(WCHAR)); - pszNameString[ret++] = 0; - } - } + if (entry) ret = copy_output_str(pszNameString, entry->u.pwszRfc822Name, cchNameString); LocalFree(altInfo); } } @@ -1359,17 +1357,8 @@ DWORD WINAPI CertGetNameStringW(PCCERT_CONTEXT pCertContext, DWORD dwType, PCERT_ALT_NAME_ENTRY entry = cert_find_alt_name_entry(pCertContext, altNameOID, CERT_ALT_NAME_DNS_NAME, &info);
- if (entry) - { - if (!pszNameString) - ret = lstrlenW(entry->u.pwszDNSName) + 1; - else if (cchNameString) - { - ret = min(lstrlenW(entry->u.pwszDNSName), cchNameString - 1); - memcpy(pszNameString, entry->u.pwszDNSName, ret * sizeof(WCHAR)); - pszNameString[ret++] = 0; - } - } + if (entry) ret = copy_output_str(pszNameString, entry->u.pwszDNSName, cchNameString); + if (info) LocalFree(info); if (!ret) @@ -1383,17 +1372,8 @@ DWORD WINAPI CertGetNameStringW(PCCERT_CONTEXT pCertContext, DWORD dwType, PCERT_ALT_NAME_ENTRY entry = cert_find_alt_name_entry(pCertContext, altNameOID, CERT_ALT_NAME_URL, &info);
- if (entry) - { - if (!pszNameString) - ret = lstrlenW(entry->u.pwszURL) + 1; - else if (cchNameString) - { - ret = min(lstrlenW(entry->u.pwszURL), cchNameString - 1); - memcpy(pszNameString, entry->u.pwszURL, ret * sizeof(WCHAR)); - pszNameString[ret++] = 0; - } - } + if (entry) ret = copy_output_str(pszNameString, entry->u.pwszURL, cchNameString); + if (info) LocalFree(info); break; @@ -1401,17 +1381,13 @@ DWORD WINAPI CertGetNameStringW(PCCERT_CONTEXT pCertContext, DWORD dwType, default: FIXME("unimplemented for type %ld\n", dwType); ret = 0; + break; } done: if (!ret) { - if (!pszNameString) - ret = 1; - else if (cchNameString) - { - pszNameString[0] = 0; - ret = 1; - } + ret = 1; + if (pszNameString && cchNameString) pszNameString[0] = 0; } return ret; } diff --git a/dlls/crypt32/tests/str.c b/dlls/crypt32/tests/str.c index 62889242e94..3009fb72c03 100644 --- a/dlls/crypt32/tests/str.c +++ b/dlls/crypt32/tests/str.c @@ -774,8 +774,7 @@ static void test_CertGetNameString_value_(unsigned int line, PCCERT_CONTEXT cont ok(!wcscmp(strW, expectedW), "line %u: unexpected value %s.\n", line, debugstr_w(strW)); strW[0] = strW[1] = 0xcccc; retlen = CertGetNameStringW(context, type, 0, type_para, strW, len - 1); - todo_wine_if(type != CERT_NAME_RDN_TYPE) - ok(retlen == len - 1, "line %u: unexpected len %lu, expected %lu.\n", line, retlen, len - 1); + ok(retlen == len - 1, "line %u: unexpected len %lu, expected %lu.\n", line, retlen, len - 1); ok(!wcsncmp(strW, expectedW, retlen - 1), "line %u: string data mismatch.\n", line); ok(!strW[retlen - 1], "line %u: string is not zero terminated.\n", line); retlen = CertGetNameStringA(context, type, 0, type_para, NULL, len - 1);
From: Paul Gofman pgofman@codeweavers.com
--- dlls/crypt32/str.c | 60 +++++++++++++++++----------------------- dlls/crypt32/tests/str.c | 8 ++++-- 2 files changed, 32 insertions(+), 36 deletions(-)
diff --git a/dlls/crypt32/str.c b/dlls/crypt32/str.c index ad0c71d697f..5ddad1ff4e6 100644 --- a/dlls/crypt32/str.c +++ b/dlls/crypt32/str.c @@ -1110,46 +1110,38 @@ BOOL WINAPI CertStrToNameW(DWORD dwCertEncodingType, LPCWSTR pszX500, return ret; }
-DWORD WINAPI CertGetNameStringA(PCCERT_CONTEXT pCertContext, DWORD dwType, - DWORD dwFlags, void *pvTypePara, LPSTR pszNameString, DWORD cchNameString) +DWORD WINAPI CertGetNameStringA(PCCERT_CONTEXT cert, DWORD type, + DWORD flags, void *type_para, LPSTR name, DWORD name_len) { - DWORD ret; + DWORD len, len_mb, ret; + LPWSTR nameW;
- TRACE("(%p, %ld, %08lx, %p, %p, %ld)\n", pCertContext, dwType, dwFlags, - pvTypePara, pszNameString, cchNameString); + TRACE("(%p, %ld, %08lx, %p, %p, %ld)\n", cert, type, flags, type_para, name, name_len);
- if (pszNameString) + len = CertGetNameStringW(cert, type, flags, type_para, NULL, 0); + + if (!(nameW = CryptMemAlloc(len * sizeof(*nameW)))) { - LPWSTR wideName; - DWORD nameLen; + ERR("No memory.\n"); + if (name && name_len) *name = 0; + return 1; + }
- nameLen = CertGetNameStringW(pCertContext, dwType, dwFlags, pvTypePara, - NULL, 0); - wideName = CryptMemAlloc(nameLen * sizeof(WCHAR)); - if (wideName) - { - CertGetNameStringW(pCertContext, dwType, dwFlags, pvTypePara, - wideName, nameLen); - nameLen = WideCharToMultiByte(CP_ACP, 0, wideName, nameLen, - pszNameString, cchNameString, NULL, NULL); - if (nameLen <= cchNameString) - ret = nameLen; - else - { - pszNameString[cchNameString - 1] = '\0'; - ret = cchNameString; - } - CryptMemFree(wideName); - } - else - { - *pszNameString = '\0'; - ret = 1; - } + len = CertGetNameStringW(cert, type, flags, type_para, nameW, len); + len_mb = WideCharToMultiByte(CP_ACP, 0, nameW, len, NULL, 0, NULL, NULL); + if (!name || !name_len) + { + CryptMemFree(nameW); + return len_mb; } - else - ret = CertGetNameStringW(pCertContext, dwType, dwFlags, pvTypePara, - NULL, 0); + + ret = WideCharToMultiByte(CP_ACP, 0, nameW, len, name, name_len, NULL, NULL); + if (ret < len_mb) + { + name[0] = 0; + ret = 1; + } + CryptMemFree(nameW); return ret; }
diff --git a/dlls/crypt32/tests/str.c b/dlls/crypt32/tests/str.c index 3009fb72c03..1cfdf8ee7b7 100644 --- a/dlls/crypt32/tests/str.c +++ b/dlls/crypt32/tests/str.c @@ -766,9 +766,13 @@ static void test_CertGetNameString_value_(unsigned int line, PCCERT_CONTEXT cont ok(!strcmp(str, expected), "line %u: unexpected value %s.\n", line, str); str[0] = str[1] = 0xcc; retlen = CertGetNameStringA(context, type, 0, type_para, str, len - 1); - todo_wine ok(retlen == 1, "line %u: Unexpected len %lu, expected 1.\n", line, retlen); - todo_wine ok(!str[0], "line %u: unexpected str[0] %#x.\n", line, str[0]); + ok(retlen == 1, "line %u: Unexpected len %lu, expected 1.\n", line, retlen); + ok(!str[0], "line %u: unexpected str[0] %#x.\n", line, str[0]); ok(str[1] == expected[1], "line %u: unexpected str[1] %#x.\n", line, str[1]); + + retlen = CertGetNameStringA(context, type, 0, type_para, str, 0); + ok(retlen == len, "line %u: Unexpected len %lu, expected 1.\n", line, retlen); + retlen = CertGetNameStringW(context, type, 0, type_para, strW, len); ok(retlen == len, "line %u: unexpected len %lu, expected 1.\n", line, retlen); ok(!wcscmp(strW, expectedW), "line %u: unexpected value %s.\n", line, debugstr_w(strW));
From: Paul Gofman pgofman@codeweavers.com
--- dlls/crypt32/str.c | 80 ++++++++++++---------------------------- dlls/crypt32/tests/str.c | 52 ++++++++++++++------------ 2 files changed, 53 insertions(+), 79 deletions(-)
diff --git a/dlls/crypt32/str.c b/dlls/crypt32/str.c index 5ddad1ff4e6..29882ab771e 100644 --- a/dlls/crypt32/str.c +++ b/dlls/crypt32/str.c @@ -29,70 +29,38 @@
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
-DWORD WINAPI CertRDNValueToStrA(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, - LPSTR psz, DWORD csz) +DWORD WINAPI CertRDNValueToStrA(DWORD type, PCERT_RDN_VALUE_BLOB value_blob, + LPSTR value, DWORD value_len) { - DWORD ret = 0, len; + DWORD len, len_mb, ret; + LPWSTR valueW;
- TRACE("(%ld, %p, %p, %ld)\n", dwValueType, pValue, psz, csz); + TRACE("(%ld, %p, %p, %ld)\n", type, value_blob, value, value_len);
- switch (dwValueType) - { - case CERT_RDN_ANY_TYPE: - break; - case CERT_RDN_NUMERIC_STRING: - case CERT_RDN_PRINTABLE_STRING: - case CERT_RDN_TELETEX_STRING: - case CERT_RDN_VIDEOTEX_STRING: - case CERT_RDN_IA5_STRING: - case CERT_RDN_GRAPHIC_STRING: - case CERT_RDN_VISIBLE_STRING: - case CERT_RDN_GENERAL_STRING: - len = pValue->cbData; - if (!psz || !csz) - ret = len; - else - { - DWORD chars = min(len, csz - 1); + len = CertRDNValueToStrW(type, value_blob, NULL, 0);
- if (chars) - { - memcpy(psz, pValue->pbData, chars); - ret += chars; - csz -= chars; - } - } - break; - case CERT_RDN_BMP_STRING: - case CERT_RDN_UTF8_STRING: - len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)pValue->pbData, - pValue->cbData / sizeof(WCHAR), NULL, 0, NULL, NULL); - if (!psz || !csz) - ret = len; - else - { - DWORD chars = min(pValue->cbData / sizeof(WCHAR), csz - 1); + if (!(valueW = CryptMemAlloc(len * sizeof(*valueW)))) + { + ERR("No memory.\n"); + if (value && value_len) *value = 0; + return 1; + }
- if (chars) - { - ret = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)pValue->pbData, - chars, psz, csz - 1, NULL, NULL); - csz -= ret; - } - } - break; - default: - FIXME("string type %ld unimplemented\n", dwValueType); + len = CertRDNValueToStrW(type, value_blob, valueW, len); + len_mb = WideCharToMultiByte(CP_ACP, 0, valueW, len, NULL, 0, NULL, NULL); + if (!value || !value_len) + { + CryptMemFree(valueW); + return len_mb; } - if (psz && csz) + + ret = WideCharToMultiByte(CP_ACP, 0, valueW, len, value, value_len, NULL, NULL); + if (ret < len_mb) { - *(psz + ret) = '\0'; - csz--; - ret++; + value[0] = 0; + ret = 1; } - else - ret++; - TRACE("returning %ld (%s)\n", ret, debugstr_a(psz)); + CryptMemFree(valueW); return ret; }
diff --git a/dlls/crypt32/tests/str.c b/dlls/crypt32/tests/str.c index 1cfdf8ee7b7..be95a796846 100644 --- a/dlls/crypt32/tests/str.c +++ b/dlls/crypt32/tests/str.c @@ -31,7 +31,6 @@ typedef struct _CertRDNAttrEncoding { DWORD dwValueType; CERT_RDN_VALUE_BLOB Value; LPCSTR str; - BOOL todo; } CertRDNAttrEncoding, *PCertRDNAttrEncoding;
typedef struct _CertRDNAttrEncodingW { @@ -133,33 +132,34 @@ static void test_CertRDNValueToStrA(void) { CertRDNAttrEncoding attrs[] = { { "2.5.4.6", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin1), bin1 }, "US", FALSE }, + { sizeof(bin1), bin1 }, "US" }, { "2.5.4.8", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin2), bin2 }, "Minnesota", FALSE }, + { sizeof(bin2), bin2 }, "Minnesota" }, { "2.5.4.7", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin3), bin3 }, "Minneapolis", FALSE }, + { sizeof(bin3), bin3 }, "Minneapolis" }, { "2.5.4.10", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin4), bin4 }, "CodeWeavers", FALSE }, + { sizeof(bin4), bin4 }, "CodeWeavers" }, { "2.5.4.11", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin5), bin5 }, "Wine Development", FALSE }, + { sizeof(bin5), bin5 }, "Wine Development" }, { "2.5.4.3", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin6), bin6 }, "localhost", FALSE }, + { sizeof(bin6), bin6 }, "localhost" }, { "1.2.840.113549.1.9.1", CERT_RDN_IA5_STRING, - { sizeof(bin7), bin7 }, "aric@codeweavers.com", FALSE }, + { sizeof(bin7), bin7 }, "aric@codeweavers.com" }, { "0", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin9), bin9 }, "abc"def", FALSE }, + { sizeof(bin9), bin9 }, "abc"def" }, { "0", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin10), bin10 }, "abc'def", FALSE }, + { sizeof(bin10), bin10 }, "abc'def" }, { "0", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin11), bin11 }, "abc, def", FALSE }, + { sizeof(bin11), bin11 }, "abc, def" }, { "0", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin12), bin12 }, " abc ", FALSE }, + { sizeof(bin12), bin12 }, " abc " }, { "0", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin13), bin13 }, ""def"", FALSE }, + { sizeof(bin13), bin13 }, ""def"" }, { "0", CERT_RDN_PRINTABLE_STRING, - { sizeof(bin14), bin14 }, "1;3", FALSE }, + { sizeof(bin14), bin14 }, "1;3" }, }; - DWORD i, ret; + unsigned int i; + DWORD ret, len; char buffer[2000]; CERT_RDN_VALUE_BLOB blob = { 0, NULL }; static const char ePKI[] = "ePKI Root Certification Authority"; @@ -177,15 +177,21 @@ static void test_CertRDNValueToStrA(void)
for (i = 0; i < ARRAY_SIZE(attrs); i++) { - ret = CertRDNValueToStrA(attrs[i].dwValueType, &attrs[i].Value, + len = CertRDNValueToStrA(attrs[i].dwValueType, &attrs[i].Value, buffer, sizeof(buffer)); - todo_wine_if (attrs[i].todo) - { - ok(ret == strlen(attrs[i].str) + 1, "Expected length %d, got %ld\n", - lstrlenA(attrs[i].str) + 1, ret); - ok(!strcmp(buffer, attrs[i].str), "Expected %s, got %s\n", - attrs[i].str, buffer); - } + ok(len == strlen(attrs[i].str) + 1, "Expected length %d, got %ld\n", + lstrlenA(attrs[i].str) + 1, ret); + ok(!strcmp(buffer, attrs[i].str), "Expected %s, got %s\n", + attrs[i].str, buffer); + memset(buffer, 0xcc, sizeof(buffer)); + ret = CertRDNValueToStrA(attrs[i].dwValueType, &attrs[i].Value, buffer, len - 1); + ok(ret == 1, "Unexpected ret %lu, expected 1, test %u.\n", ret, i); + ok(!buffer[0], "Unexpected value %#x, test %u.\n", buffer[0], i); + ok(!strncmp(buffer + 1, attrs[i].str + 1, len - 2), "Strings do not match, test %u.\n", i); + memset(buffer, 0xcc, sizeof(buffer)); + ret = CertRDNValueToStrA(attrs[i].dwValueType, &attrs[i].Value, buffer, 0); + ok(ret == len, "Unexpected ret %lu, expected %lu, test %u.\n", ret, len, i); + ok((unsigned char)buffer[0] == 0xcc, "Unexpected value %#x, test %u.\n", buffer[0], i); } blob.pbData = bin8; blob.cbData = sizeof(bin8);
From: Paul Gofman pgofman@codeweavers.com
--- dlls/crypt32/str.c | 250 ++++----------------------------------- dlls/crypt32/tests/str.c | 107 ++++++++--------- 2 files changed, 72 insertions(+), 285 deletions(-)
diff --git a/dlls/crypt32/str.c b/dlls/crypt32/str.c index 29882ab771e..2c667542dc8 100644 --- a/dlls/crypt32/str.c +++ b/dlls/crypt32/str.c @@ -141,115 +141,6 @@ static inline BOOL is_quotable_char(WCHAR c) } }
-static DWORD quote_rdn_value_to_str_a(DWORD dwValueType, - PCERT_RDN_VALUE_BLOB pValue, LPSTR psz, DWORD csz) -{ - DWORD ret = 0, len, i; - BOOL needsQuotes = FALSE; - - TRACE("(%ld, %p, %p, %ld)\n", dwValueType, pValue, psz, csz); - - switch (dwValueType) - { - case CERT_RDN_ANY_TYPE: - break; - case CERT_RDN_NUMERIC_STRING: - case CERT_RDN_PRINTABLE_STRING: - case CERT_RDN_TELETEX_STRING: - case CERT_RDN_VIDEOTEX_STRING: - case CERT_RDN_IA5_STRING: - case CERT_RDN_GRAPHIC_STRING: - case CERT_RDN_VISIBLE_STRING: - case CERT_RDN_GENERAL_STRING: - len = pValue->cbData; - if (pValue->cbData && isspace(pValue->pbData[0])) - needsQuotes = TRUE; - if (pValue->cbData && isspace(pValue->pbData[pValue->cbData - 1])) - needsQuotes = TRUE; - for (i = 0; i < pValue->cbData; i++) - { - if (is_quotable_char(pValue->pbData[i])) - needsQuotes = TRUE; - if (pValue->pbData[i] == '"') - len += 1; - } - if (needsQuotes) - len += 2; - if (!psz || !csz) - ret = len; - else - { - char *ptr = psz; - - if (needsQuotes) - *ptr++ = '"'; - for (i = 0; i < pValue->cbData && ptr - psz < csz; ptr++, i++) - { - *ptr = pValue->pbData[i]; - if (pValue->pbData[i] == '"' && ptr - psz < csz - 1) - *(++ptr) = '"'; - } - if (needsQuotes && ptr - psz < csz) - *ptr++ = '"'; - ret = ptr - psz; - } - break; - case CERT_RDN_BMP_STRING: - case CERT_RDN_UTF8_STRING: - len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)pValue->pbData, - pValue->cbData / sizeof(WCHAR), NULL, 0, NULL, NULL); - if (pValue->cbData && iswspace(((LPCWSTR)pValue->pbData)[0])) - needsQuotes = TRUE; - if (pValue->cbData && - iswspace(((LPCWSTR)pValue->pbData)[pValue->cbData / sizeof(WCHAR)-1])) - needsQuotes = TRUE; - for (i = 0; i < pValue->cbData / sizeof(WCHAR); 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 - { - char *dst = psz; - - if (needsQuotes) - *dst++ = '"'; - for (i = 0; i < pValue->cbData / sizeof(WCHAR) && - dst - psz < csz; dst++, i++) - { - LPCWSTR src = (LPCWSTR)pValue->pbData + i; - - WideCharToMultiByte(CP_ACP, 0, src, 1, dst, - csz - (dst - psz) - 1, NULL, NULL); - if (*src == '"' && dst - psz < csz - 1) - *(++dst) = '"'; - } - if (needsQuotes && dst - psz < csz) - *dst++ = '"'; - ret = dst - psz; - } - break; - default: - FIXME("string type %ld unimplemented\n", dwValueType); - } - if (psz && csz) - { - *(psz + ret) = '\0'; - csz--; - ret++; - } - else - ret++; - TRACE("returning %ld (%s)\n", ret, debugstr_a(psz)); - return ret; -} - static DWORD quote_rdn_value_to_str_w(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue, LPWSTR psz, DWORD csz) { @@ -345,136 +236,37 @@ static DWORD quote_rdn_value_to_str_w(DWORD dwValueType, return ret; }
-/* Adds the prefix prefix to the string pointed to by psz, followed by the - * character '='. Copies no more than csz characters. Returns the number of - * characters copied. If psz is NULL, returns the number of characters that - * would be copied. - */ -static DWORD CRYPT_AddPrefixA(LPCSTR prefix, LPSTR psz, DWORD csz) +DWORD WINAPI CertNameToStrA(DWORD encoding_type, PCERT_NAME_BLOB name_blob, DWORD str_type, LPSTR str, DWORD str_len) { - DWORD chars; + DWORD len, len_mb, ret; + LPWSTR strW;
- TRACE("(%s, %p, %ld)\n", debugstr_a(prefix), psz, csz); + TRACE("(%ld, %p, %08lx, %p, %ld)\n", encoding_type, name_blob, str_type, str, str_len);
- if (psz) + len = CertNameToStrW(encoding_type, name_blob, str_type, NULL, 0); + + if (!(strW = CryptMemAlloc(len * sizeof(*strW)))) { - chars = min(strlen(prefix), csz); - memcpy(psz, prefix, chars); - *(psz + chars) = '='; - chars++; + ERR("No memory.\n"); + if (str && str_len) *str = 0; + return 1; } - else - chars = lstrlenA(prefix) + 1; - return chars; -}
-DWORD WINAPI CertNameToStrA(DWORD dwCertEncodingType, PCERT_NAME_BLOB pName, - DWORD dwStrType, LPSTR psz, DWORD csz) -{ - static const DWORD unsupportedFlags = CERT_NAME_STR_NO_QUOTING_FLAG | - CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG; - static const char commaSep[] = ", "; - static const char semiSep[] = "; "; - static const char crlfSep[] = "\r\n"; - static const char plusSep[] = " + "; - static const char spaceSep[] = " "; - DWORD ret = 0, bytes = 0; - BOOL bRet; - CERT_NAME_INFO *info; - - TRACE("(%ld, %p, %08lx, %p, %ld)\n", dwCertEncodingType, pName, dwStrType, - psz, csz); - if (dwStrType & unsupportedFlags) - FIXME("unsupported flags: %08lx\n", dwStrType & unsupportedFlags); - - bRet = CryptDecodeObjectEx(dwCertEncodingType, X509_NAME, pName->pbData, - pName->cbData, CRYPT_DECODE_ALLOC_FLAG, NULL, &info, &bytes); - if (bRet) + len = CertNameToStrW(encoding_type, name_blob, str_type, strW, len); + len_mb = WideCharToMultiByte(CP_ACP, 0, strW, len, NULL, 0, NULL, NULL); + if (!str || !str_len) { - DWORD i, j, sepLen, rdnSepLen; - LPCSTR sep, rdnSep; - BOOL reverse = dwStrType & CERT_NAME_STR_REVERSE_FLAG; - const CERT_RDN *rdn = info->rgRDN; - - if(reverse && info->cRDN > 1) rdn += (info->cRDN - 1); - - if (dwStrType & CERT_NAME_STR_SEMICOLON_FLAG) - sep = semiSep; - else if (dwStrType & CERT_NAME_STR_CRLF_FLAG) - sep = crlfSep; - else - sep = commaSep; - sepLen = strlen(sep); - if (dwStrType & CERT_NAME_STR_NO_PLUS_FLAG) - rdnSep = spaceSep; - else - rdnSep = plusSep; - rdnSepLen = strlen(rdnSep); - for (i = 0; (!psz || ret < csz) && i < info->cRDN; i++) - { - for (j = 0; (!psz || ret < csz) && j < rdn->cRDNAttr; j++) - { - DWORD chars; - char prefixBuf[13]; /* big enough for SERIALNUMBER */ - LPCSTR prefix = NULL; - - if ((dwStrType & 0x000000ff) == CERT_OID_NAME_STR) - prefix = rdn->rgRDNAttr[j].pszObjId; - else if ((dwStrType & 0x000000ff) == CERT_X500_NAME_STR) - { - PCCRYPT_OID_INFO oidInfo = CryptFindOIDInfo( - CRYPT_OID_INFO_OID_KEY, - rdn->rgRDNAttr[j].pszObjId, - CRYPT_RDN_ATTR_OID_GROUP_ID); - - if (oidInfo) - { - WideCharToMultiByte(CP_ACP, 0, oidInfo->pwszName, -1, - prefixBuf, sizeof(prefixBuf), NULL, NULL); - prefix = prefixBuf; - } - else - prefix = rdn->rgRDNAttr[j].pszObjId; - } - if (prefix) - { - /* - 1 is needed to account for the NULL terminator. */ - chars = CRYPT_AddPrefixA(prefix, - psz ? psz + ret : NULL, psz ? csz - ret - 1 : 0); - ret += chars; - } - chars = quote_rdn_value_to_str_a( - rdn->rgRDNAttr[j].dwValueType, - &rdn->rgRDNAttr[j].Value, psz ? psz + ret : NULL, - psz ? csz - ret : 0); - if (chars) - ret += chars - 1; - if (j < rdn->cRDNAttr - 1) - { - if (psz && ret < csz - rdnSepLen - 1) - memcpy(psz + ret, rdnSep, rdnSepLen); - ret += rdnSepLen; - } - } - if (i < info->cRDN - 1) - { - if (psz && ret < csz - sepLen - 1) - memcpy(psz + ret, sep, sepLen); - ret += sepLen; - } - if(reverse) rdn--; - else rdn++; - } - LocalFree(info); + CryptMemFree(strW); + return len_mb; } - if (psz && csz) + + ret = WideCharToMultiByte(CP_ACP, 0, strW, len, str, str_len, NULL, NULL); + if (ret < len_mb) { - *(psz + ret) = '\0'; - ret++; + str[0] = 0; + ret = 1; } - else - ret++; - TRACE("Returning %s\n", debugstr_a(psz)); + CryptMemFree(strW); return ret; }
diff --git a/dlls/crypt32/tests/str.c b/dlls/crypt32/tests/str.c index be95a796846..d2106b728a9 100644 --- a/dlls/crypt32/tests/str.c +++ b/dlls/crypt32/tests/str.c @@ -276,24 +276,27 @@ static void test_CertRDNValueToStrW(void) wine_dbgstr_w(ePKIW), wine_dbgstr_w(buffer)); }
-static void test_NameToStrConversionA(PCERT_NAME_BLOB pName, DWORD dwStrType, - LPCSTR expected, BOOL todo) +#define test_NameToStrConversionA(a, b, c) test_NameToStrConversionA_(__LINE__, a, b, c) +static void test_NameToStrConversionA_(unsigned int line, PCERT_NAME_BLOB pName, DWORD dwStrType, LPCSTR expected) { - char buffer[2000] = { 0 }; - DWORD i; - - i = CertNameToStrA(X509_ASN_ENCODING, pName, dwStrType, NULL, 0); - todo_wine_if (todo) - ok(i == strlen(expected) + 1, "Expected %d chars, got %ld\n", - lstrlenA(expected) + 1, i); - i = CertNameToStrA(X509_ASN_ENCODING,pName, dwStrType, buffer, - sizeof(buffer)); - todo_wine_if (todo) - ok(i == strlen(expected) + 1, "Expected %d chars, got %ld\n", - lstrlenA(expected) + 1, i); - todo_wine_if (todo) - ok(!strcmp(buffer, expected), "Expected %s, got %s\n", expected, - buffer); + char buffer[2000]; + DWORD len, retlen; + + len = CertNameToStrA(X509_ASN_ENCODING, pName, dwStrType, NULL, 0); + ok(len == strlen(expected) + 1, "line %u: Expected %d chars, got %ld.\n", line, lstrlenA(expected) + 1, len); + len = CertNameToStrA(X509_ASN_ENCODING,pName, dwStrType, buffer, sizeof(buffer)); + ok(len == strlen(expected) + 1, "line %u: Expected %d chars, got %ld.\n", line, lstrlenA(expected) + 1, len); + ok(!strcmp(buffer, expected), "line %u: Expected %s, got %s.\n", line, expected, buffer); + + memset(buffer, 0xcc, sizeof(buffer)); + retlen = CertNameToStrA(X509_ASN_ENCODING, pName, dwStrType, buffer, len - 1); + ok(retlen == 1, "line %u: expected 1, got %lu\n", line, retlen); + ok(!buffer[0], "line %u: string is not zero terminated.\n", line); + + memset(buffer, 0xcc, sizeof(buffer)); + retlen = CertNameToStrA(X509_ASN_ENCODING, pName, dwStrType, buffer, 0); + ok(retlen == len, "line %u: expected %lu chars, got %lu\n", line, len - 1, retlen); + ok((unsigned char)buffer[0] == 0xcc, "line %u: got %s\n", line, wine_dbgstr_a(buffer)); }
static BYTE encodedSimpleCN[] = { @@ -366,79 +369,71 @@ static void test_CertNameToStrA(void) "Expected positive return and ERROR_SUCCESS, got %ld - %08lx\n", ret, GetLastError());
+ test_NameToStrConversionA(&context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR, issuerStr); test_NameToStrConversionA(&context->pCertInfo->Issuer, - CERT_SIMPLE_NAME_STR, issuerStr, FALSE); - test_NameToStrConversionA(&context->pCertInfo->Issuer, - CERT_SIMPLE_NAME_STR | CERT_NAME_STR_SEMICOLON_FLAG, - issuerStrSemicolon, FALSE); + CERT_SIMPLE_NAME_STR | CERT_NAME_STR_SEMICOLON_FLAG, issuerStrSemicolon); test_NameToStrConversionA(&context->pCertInfo->Issuer, - CERT_SIMPLE_NAME_STR | CERT_NAME_STR_CRLF_FLAG, - issuerStrCRLF, FALSE); + CERT_SIMPLE_NAME_STR | CERT_NAME_STR_CRLF_FLAG, issuerStrCRLF); + test_NameToStrConversionA(&context->pCertInfo->Subject, CERT_OID_NAME_STR, subjectStr); test_NameToStrConversionA(&context->pCertInfo->Subject, - CERT_OID_NAME_STR, subjectStr, FALSE); + CERT_OID_NAME_STR | CERT_NAME_STR_SEMICOLON_FLAG, subjectStrSemicolon); test_NameToStrConversionA(&context->pCertInfo->Subject, - CERT_OID_NAME_STR | CERT_NAME_STR_SEMICOLON_FLAG, - subjectStrSemicolon, FALSE); - test_NameToStrConversionA(&context->pCertInfo->Subject, - CERT_OID_NAME_STR | CERT_NAME_STR_CRLF_FLAG, - subjectStrCRLF, FALSE); + CERT_OID_NAME_STR | CERT_NAME_STR_CRLF_FLAG, subjectStrCRLF); test_NameToStrConversionA(&context->pCertInfo->Subject, - CERT_X500_NAME_STR, x500SubjectStr, FALSE); + CERT_X500_NAME_STR, x500SubjectStr); test_NameToStrConversionA(&context->pCertInfo->Subject, CERT_X500_NAME_STR | CERT_NAME_STR_SEMICOLON_FLAG | CERT_NAME_STR_REVERSE_FLAG, - x500SubjectStrSemicolonReverse, FALSE); + x500SubjectStrSemicolonReverse);
CertFreeCertificateContext(context); } blob.pbData = encodedSimpleCN; blob.cbData = sizeof(encodedSimpleCN); - test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=1", FALSE); + test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=1"); blob.pbData = encodedSingleQuotedCN; blob.cbData = sizeof(encodedSingleQuotedCN); - test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN='1'", FALSE); - test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, "'1'", FALSE); + test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN='1'"); + test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, "'1'"); blob.pbData = encodedSpacedCN; blob.cbData = sizeof(encodedSpacedCN); - test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=" 1 "", FALSE); - test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, "" 1 "", FALSE); + test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=" 1 ""); + test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, "" 1 ""); blob.pbData = encodedQuotedCN; blob.cbData = sizeof(encodedQuotedCN); - test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN="""1"""", - FALSE); - test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, """"1"""", - FALSE); + test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN="""1""""); + test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, """"1""""); blob.pbData = encodedMultipleAttrCN; blob.cbData = sizeof(encodedMultipleAttrCN); - test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN="1+2"", FALSE); - test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, ""1+2"", FALSE); + test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN="1+2""); + test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, ""1+2""); blob.pbData = encodedCommaCN; blob.cbData = sizeof(encodedCommaCN); - test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN="a,b"", FALSE); - test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, ""a,b"", FALSE); + test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN="a,b""); + test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, ""a,b""); blob.pbData = encodedEqualCN; blob.cbData = sizeof(encodedEqualCN); - test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN="a=b"", FALSE); - test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, ""a=b"", FALSE); + test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN="a=b""); + test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, ""a=b""); blob.pbData = encodedLessThanCN; blob.cbData = sizeof(encodedLessThanCN); - test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN="<"", FALSE); - test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, ""<"", FALSE); + test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN="<""); + test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, ""<""); blob.pbData = encodedGreaterThanCN; blob.cbData = sizeof(encodedGreaterThanCN); - test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=">"", FALSE); - test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, "">"", FALSE); + test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=">""); + test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, "">""); blob.pbData = encodedHashCN; blob.cbData = sizeof(encodedHashCN); - test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN="#"", FALSE); - test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, ""#"", FALSE); + test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN="#""); + test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, ""#""); blob.pbData = encodedSemiCN; blob.cbData = sizeof(encodedSemiCN); - test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=";"", FALSE); - test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, "";"", FALSE); + test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN=";""); + test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, "";""); blob.pbData = encodedNewlineCN; blob.cbData = sizeof(encodedNewlineCN); - test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN="a\nb"", FALSE); - test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, ""a\nb"", FALSE); + test_NameToStrConversionA(&blob, CERT_X500_NAME_STR, "CN="a\nb""); + test_NameToStrConversionA(&blob, CERT_SIMPLE_NAME_STR, ""a\nb""); }
#define test_NameToStrConversionW(a, b, c) test_NameToStrConversionW_(__LINE__, a, b, c)