Commit da605a93 authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

cryptnet: Don't access URL cache entry before it's been read.

parent f50b2c23
......@@ -405,28 +405,29 @@ static BOOL CRYPT_GetObjectFromCache(LPCWSTR pszURL, PCRYPT_BLOB_ARRAY pObject,
PCRYPT_RETRIEVE_AUX_INFO pAuxInfo)
{
BOOL ret = FALSE;
INTERNET_CACHE_ENTRY_INFOW cacheInfo = { sizeof(cacheInfo), 0 };
DWORD size = sizeof(cacheInfo);
INTERNET_CACHE_ENTRY_INFOW *pCacheInfo = NULL;
DWORD size = 0;
TRACE("(%s, %p, %p)\n", debugstr_w(pszURL), pObject, pAuxInfo);
if (GetUrlCacheEntryInfoW(pszURL, &cacheInfo, &size) ||
GetLastError() == ERROR_INSUFFICIENT_BUFFER)
ret = GetUrlCacheEntryInfoW(pszURL, NULL, &size);
if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
pCacheInfo = CryptMemAlloc(size);
if (pCacheInfo)
ret = TRUE;
else
SetLastError(ERROR_OUTOFMEMORY);
}
if (ret && (ret = GetUrlCacheEntryInfoW(pszURL, pCacheInfo, &size)))
{
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
if (CompareFileTime(&cacheInfo.ExpireTime, &ft) >= 0)
{
LPINTERNET_CACHE_ENTRY_INFOW pCacheInfo = CryptMemAlloc(size);
if (pCacheInfo)
{
if (GetUrlCacheEntryInfoW(pszURL, pCacheInfo, &size))
if (CompareFileTime(&pCacheInfo->ExpireTime, &ft) >= 0)
{
HANDLE hFile = CreateFileW(pCacheInfo->lpszLocalFileName,
GENERIC_READ, 0, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
......@@ -442,15 +443,19 @@ static BOOL CRYPT_GetObjectFromCache(LPCWSTR pszURL, PCRYPT_BLOB_ARRAY pObject,
}
CloseHandle(hFile);
}
}
CryptMemFree(pCacheInfo);
}
else
SetLastError(ERROR_OUTOFMEMORY);
{
DeleteUrlCacheEntryW(pszURL);
ret = FALSE;
}
}
else
{
DeleteUrlCacheEntryW(pszURL);
ret = FALSE;
}
}
CryptMemFree(pCacheInfo);
TRACE("returning %d\n", 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