Commit bc96cfac authored by Paul Gofman's avatar Paul Gofman Committed by Alexandre Julliard

crypt32: Fix filling short output in CertGetNameStringA().

parent 66d9250c
......@@ -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;
}
......
......@@ -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));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment