From 7aa82c80d482dfb6c3b84a09a9ded55c4e8919f3 Mon Sep 17 00:00:00 2001 From: James Hawkins Date: Fri, 13 Aug 2004 19:45:40 +0000 Subject: [PATCH] If the pszProvName param of CryptEnumProviders is too small to hold the provider name, SetLastError to ERROR_MORE_DATA. --- dlls/advapi32/crypt.c | 15 +++++++++------ dlls/advapi32/tests/crypt.c | 23 ++++++++++------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/dlls/advapi32/crypt.c b/dlls/advapi32/crypt.c index d114f8e0a30..b74fc0496b4 100644 --- a/dlls/advapi32/crypt.c +++ b/dlls/advapi32/crypt.c @@ -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 diff --git a/dlls/advapi32/tests/crypt.c b/dlls/advapi32/tests/crypt.c index 855d65d9b28..c4b18d4c17d 100644 --- a/dlls/advapi32/tests/crypt.c +++ b/dlls/advapi32/tests/crypt.c @@ -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 */