Commit 7aa82c80 authored by James Hawkins's avatar James Hawkins Committed by Alexandre Julliard

If the pszProvName param of CryptEnumProviders is too small to hold

the provider name, SetLastError to ERROR_MORE_DATA.
parent fb504265
......@@ -941,7 +941,7 @@ BOOL WINAPI CryptEncrypt (HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final,
/******************************************************************************
* CryptEnumProvidersW (ADVAPI32.@)
*
* Returns the next availabe CPS.
* Returns the next availabe CSP.
*
* PARAMS
* dwIndex [I] Index of the next provider to be enumerated.
......@@ -950,14 +950,14 @@ BOOL WINAPI CryptEncrypt (HCRYPTKEY hKey, HCRYPTHASH hHash, BOOL Final,
* pdwProvType [O] DWORD designating the type of the provider.
* pszProvName [O] Buffer that receives data from the provider.
* pcbProvName [I/O] Specifies the size of pszProvName. Contains the number
* of bytes stored in the buffer no return.
* of bytes stored in the buffer on return.
*
* RETURNS
* Success: TRUE
* Failure: FALSE
*
* NOTES
* If pszProvName is NULL, CryptEnumProvidersA sets the size of the name
* If pszProvName is NULL, CryptEnumProvidersW sets the size of the name
* for memory allocation purposes.
*/
BOOL WINAPI CryptEnumProvidersW (DWORD dwIndex, DWORD *pdwReserved,
......@@ -1005,9 +1005,12 @@ BOOL WINAPI CryptEnumProvidersW (DWORD dwIndex, DWORD *pdwReserved,
CRYPT_ReturnLastError(ERROR_NO_MORE_ITEMS);
} else {
DWORD size = sizeof(DWORD);
DWORD result;
HKEY subkey;
if (RegEnumKeyW(hKey, dwIndex, pszProvName, *pcbProvName / sizeof(WCHAR)))
return FALSE;
result = RegEnumKeyW(hKey, dwIndex, pszProvName, *pcbProvName / sizeof(WCHAR));
if (result)
CRYPT_ReturnLastError(result);
if (RegOpenKeyW(hKey, pszProvName, &subkey))
return FALSE;
if (RegQueryValueExW(subkey, typeW, NULL, NULL, (BYTE*)pdwProvType, &size))
......@@ -1058,7 +1061,7 @@ BOOL WINAPI CryptEnumProvidersA (DWORD dwIndex, DWORD *pdwReserved,
* pdwProvType [O] DWORD designating the type of the provider.
* pszTypeName [O] Buffer that receives data from the provider type.
* pcbTypeName [I/O] Specifies the size of pszTypeName. Contains the number
* of bytes stored in the buffer no return.
* of bytes stored in the buffer on return.
*
* RETURNS
* Success: TRUE
......
......@@ -179,19 +179,16 @@ static void test_enum_providers(void)
/* alloc provider to half the size required
* cbName holds the size required */
todo_wine
{
providerLen = cbName / 2;
if (!(provider = ((LPSTR)LocalAlloc(LMEM_ZEROINIT, providerLen))))
return;
result = CryptEnumProviders(dwIndex, NULL, 0, &type, provider, &providerLen);
ok(!result && GetLastError()==ERROR_MORE_DATA, "expected %08x, got %08x\n",
ERROR_MORE_DATA, (unsigned int)GetLastError());
LocalFree(provider);
}
providerLen = cbName / 2;
if (!(provider = ((LPSTR)LocalAlloc(LMEM_ZEROINIT, providerLen))))
return;
result = CryptEnumProviders(dwIndex, NULL, 0, &type, provider, &providerLen);
ok(!result && GetLastError()==ERROR_MORE_DATA, "expected %08x, got %08x\n",
ERROR_MORE_DATA, (unsigned int)GetLastError());
LocalFree(provider);
/* loop through the providers to get the number of providers
* after loop ends, count should be provCount + 1 so subtract 1
* to get actual number of providers */
......
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