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

This commit is contained in:
Juan Lang 2008-10-03 10:50:34 -07:00 committed by Alexandre Julliard
parent f50b2c237d
commit da605a935b
1 changed files with 33 additions and 28 deletions

View File

@ -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);
}
else
{
DeleteUrlCacheEntryW(pszURL);
ret = FALSE;
}
}
else
{
DeleteUrlCacheEntryW(pszURL);
ret = FALSE;
}
}
CryptMemFree(pCacheInfo);
}
else
SetLastError(ERROR_OUTOFMEMORY);
}
else
DeleteUrlCacheEntryW(pszURL);
}
TRACE("returning %d\n", ret);
return ret;
}