Commit 7cf611ef authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

crypt32: Fail if MultiByteToWideChar converts 0 characters.

parent 533aa4dc
...@@ -455,7 +455,6 @@ BOOL WINAPI CertStrToNameA(DWORD dwCertEncodingType, LPCSTR pszX500, ...@@ -455,7 +455,6 @@ BOOL WINAPI CertStrToNameA(DWORD dwCertEncodingType, LPCSTR pszX500,
DWORD dwStrType, void *pvReserved, BYTE *pbEncoded, DWORD *pcbEncoded, DWORD dwStrType, void *pvReserved, BYTE *pbEncoded, DWORD *pcbEncoded,
LPCSTR *ppszError) LPCSTR *ppszError)
{ {
LPWSTR x500, errorStr;
BOOL ret; BOOL ret;
int len; int len;
...@@ -464,24 +463,39 @@ BOOL WINAPI CertStrToNameA(DWORD dwCertEncodingType, LPCSTR pszX500, ...@@ -464,24 +463,39 @@ BOOL WINAPI CertStrToNameA(DWORD dwCertEncodingType, LPCSTR pszX500,
ppszError); ppszError);
len = MultiByteToWideChar(CP_ACP, 0, pszX500, -1, NULL, 0); len = MultiByteToWideChar(CP_ACP, 0, pszX500, -1, NULL, 0);
x500 = CryptMemAlloc(len * sizeof(WCHAR)); if (len)
if (x500)
{ {
MultiByteToWideChar(CP_ACP, 0, pszX500, -1, x500, len); LPWSTR x500, errorStr;
ret = CertStrToNameW(dwCertEncodingType, x500, dwStrType, pvReserved,
pbEncoded, pcbEncoded, ppszError ? (LPCWSTR *)&errorStr : NULL); if ((x500 = CryptMemAlloc(len * sizeof(WCHAR))))
if (ppszError)
{ {
DWORD i; MultiByteToWideChar(CP_ACP, 0, pszX500, -1, x500, len);
ret = CertStrToNameW(dwCertEncodingType, x500, dwStrType,
pvReserved, pbEncoded, pcbEncoded,
ppszError ? (LPCWSTR *)&errorStr : NULL);
if (ppszError)
{
DWORD i;
*ppszError = pszX500; *ppszError = pszX500;
for (i = 0; i < errorStr - x500; i++) for (i = 0; i < errorStr - x500; i++)
*ppszError = CharNextA(*ppszError); *ppszError = CharNextA(*ppszError);
}
CryptMemFree(x500);
}
else
{
SetLastError(ERROR_OUTOFMEMORY);
ret = FALSE;
} }
CryptMemFree(x500);
} }
else else
{
SetLastError(CRYPT_E_INVALID_X500_STRING);
if (ppszError)
*ppszError = pszX500;
ret = FALSE; ret = FALSE;
}
return ret; return ret;
} }
......
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