wininet: Moved critical section locking to get_cookie callers so that cookie_set_t is also protected.

This commit is contained in:
Jacek Caban 2014-09-17 12:09:13 +02:00 committed by Alexandre Julliard
parent 40456439e6
commit c639e757d5
1 changed files with 43 additions and 35 deletions

View File

@ -576,8 +576,6 @@ static DWORD get_cookie(const WCHAR *host, const WCHAR *path, DWORD flags, cooki
GetSystemTimeAsFileTime(&tm); GetSystemTimeAsFileTime(&tm);
EnterCriticalSection(&cookie_cs);
len = strlenW(host); len = strlenW(host);
p = host+len; p = host+len;
while(p>host && p[-1]!='.') p--; while(p>host && p[-1]!='.') p--;
@ -604,7 +602,6 @@ static DWORD get_cookie(const WCHAR *host, const WCHAR *path, DWORD flags, cooki
domain = get_cookie_domain(host, FALSE); domain = get_cookie_domain(host, FALSE);
if(!domain) { if(!domain) {
TRACE("Unknown host %s\n", debugstr_w(host)); TRACE("Unknown host %s\n", debugstr_w(host));
LeaveCriticalSection(&cookie_cs);
return ERROR_NO_MORE_ITEMS; return ERROR_NO_MORE_ITEMS;
} }
@ -660,7 +657,6 @@ static DWORD get_cookie(const WCHAR *host, const WCHAR *path, DWORD flags, cooki
} }
} }
LeaveCriticalSection(&cookie_cs);
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
@ -694,23 +690,23 @@ static void cookie_set_to_string(const cookie_set_t *cookie_set, WCHAR *str)
DWORD get_cookie_header(const WCHAR *host, const WCHAR *path, WCHAR **ret) DWORD get_cookie_header(const WCHAR *host, const WCHAR *path, WCHAR **ret)
{ {
cookie_set_t cookie_set = {0}; cookie_set_t cookie_set = {0};
WCHAR *header, *ptr;
DWORD res; DWORD res;
static const WCHAR cookieW[] = {'C','o','o','k','i','e',':',' '}; static const WCHAR cookieW[] = {'C','o','o','k','i','e',':',' '};
EnterCriticalSection(&cookie_cs);
res = get_cookie(host, path, INTERNET_COOKIE_HTTPONLY, &cookie_set); res = get_cookie(host, path, INTERNET_COOKIE_HTTPONLY, &cookie_set);
if(res != ERROR_SUCCESS) if(res != ERROR_SUCCESS) {
LeaveCriticalSection(&cookie_cs);
return res; return res;
if(!cookie_set.cnt) {
*ret = NULL;
return ERROR_SUCCESS;
} }
ptr = header = heap_alloc(sizeof(cookieW) + (cookie_set.string_len + 3 /* crlf0 */) * sizeof(WCHAR)); if(cookie_set.cnt) {
if(!header) WCHAR *header, *ptr;
return ERROR_NOT_ENOUGH_MEMORY;
ptr = header = heap_alloc(sizeof(cookieW) + (cookie_set.string_len + 3 /* crlf0 */) * sizeof(WCHAR));
if(header) {
memcpy(ptr, cookieW, sizeof(cookieW)); memcpy(ptr, cookieW, sizeof(cookieW));
ptr += sizeof(cookieW)/sizeof(*cookieW); ptr += sizeof(cookieW)/sizeof(*cookieW);
@ -723,6 +719,14 @@ DWORD get_cookie_header(const WCHAR *host, const WCHAR *path, WCHAR **ret)
*ptr++ = 0; *ptr++ = 0;
*ret = header; *ret = header;
}else {
res = ERROR_NOT_ENOUGH_MEMORY;
}
}else {
*ret = NULL;
}
LeaveCriticalSection(&cookie_cs);
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
@ -765,18 +769,16 @@ BOOL WINAPI InternetGetCookieExW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
return FALSE; return FALSE;
} }
EnterCriticalSection(&cookie_cs);
res = get_cookie(host, path, flags, &cookie_set); res = get_cookie(host, path, flags, &cookie_set);
if(res != ERROR_SUCCESS) { if(res != ERROR_SUCCESS) {
LeaveCriticalSection(&cookie_cs);
SetLastError(res); SetLastError(res);
return FALSE; return FALSE;
} }
if(!cookie_set.cnt) { if(cookie_set.cnt) {
TRACE("no cookies found for %s\n", debugstr_w(host));
SetLastError(ERROR_NO_MORE_ITEMS);
return FALSE;
}
if(!lpCookieData || cookie_set.string_len+1 > *lpdwSize) { if(!lpCookieData || cookie_set.string_len+1 > *lpdwSize) {
*lpdwSize = (cookie_set.string_len + 1) * sizeof(WCHAR); *lpdwSize = (cookie_set.string_len + 1) * sizeof(WCHAR);
TRACE("returning %u\n", *lpdwSize); TRACE("returning %u\n", *lpdwSize);
@ -789,8 +791,14 @@ BOOL WINAPI InternetGetCookieExW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName,
cookie_set_to_string(&cookie_set, lpCookieData); cookie_set_to_string(&cookie_set, lpCookieData);
lpCookieData[cookie_set.string_len] = 0; lpCookieData[cookie_set.string_len] = 0;
} }
}else {
TRACE("no cookies found for %s\n", debugstr_w(host));
SetLastError(ERROR_NO_MORE_ITEMS);
return FALSE;
}
heap_free(cookie_set.cookies); heap_free(cookie_set.cookies);
LeaveCriticalSection(&cookie_cs);
return ret; return ret;
} }