Piotr Caban : cryptnet: Lock cache file while accessing it.

Alexandre Julliard julliard at winehq.org
Fri Mar 8 14:00:37 CST 2013


Module: wine
Branch: master
Commit: 4f8932157799e4d7e2c182bb0b66aa4e161992fa
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=4f8932157799e4d7e2c182bb0b66aa4e161992fa

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Fri Mar  8 11:17:11 2013 +0100

cryptnet: Lock cache file while accessing it.

---

 dlls/cryptnet/cryptnet_main.c |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/dlls/cryptnet/cryptnet_main.c b/dlls/cryptnet/cryptnet_main.c
index 46eac4e..75dce9d 100644
--- a/dlls/cryptnet/cryptnet_main.c
+++ b/dlls/cryptnet/cryptnet_main.c
@@ -503,24 +503,26 @@ static BOOL CRYPT_GetObjectFromCache(LPCWSTR pszURL, PCRYPT_BLOB_ARRAY pObject,
 
     TRACE("(%s, %p, %p)\n", debugstr_w(pszURL), pObject, pAuxInfo);
 
-    ret = GetUrlCacheEntryInfoW(pszURL, NULL, &size);
-    if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
+    RetrieveUrlCacheEntryFileW(pszURL, NULL, &size, 0);
+    if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
+        return FALSE;
+
+    pCacheInfo = CryptMemAlloc(size);
+    if (!pCacheInfo)
     {
-        pCacheInfo = CryptMemAlloc(size);
-        if (pCacheInfo)
-            ret = TRUE;
-        else
-            SetLastError(ERROR_OUTOFMEMORY);
+        SetLastError(ERROR_OUTOFMEMORY);
+        return FALSE;
     }
-    if (ret && (ret = GetUrlCacheEntryInfoW(pszURL, pCacheInfo, &size)))
+
+    if ((ret = RetrieveUrlCacheEntryFileW(pszURL, pCacheInfo, &size, 0)))
     {
         FILETIME ft;
 
         GetSystemTimeAsFileTime(&ft);
         if (CompareFileTime(&pCacheInfo->ExpireTime, &ft) >= 0)
         {
-            HANDLE hFile = CreateFileW(pCacheInfo->lpszLocalFileName,
-             GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+            HANDLE hFile = CreateFileW(pCacheInfo->lpszLocalFileName, GENERIC_READ,
+             FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
 
             if (hFile != INVALID_HANDLE_VALUE)
             {
@@ -547,6 +549,7 @@ static BOOL CRYPT_GetObjectFromCache(LPCWSTR pszURL, PCRYPT_BLOB_ARRAY pObject,
             DeleteUrlCacheEntryW(pszURL);
             ret = FALSE;
         }
+        UnlockUrlCacheEntryFileW(pszURL, 0);
     }
     CryptMemFree(pCacheInfo);
     TRACE("returning %d\n", ret);




More information about the wine-cvs mailing list