diff --git a/dlls/wininet/cookie.c b/dlls/wininet/cookie.c index 80bd8ea58b0..043de1bca79 100644 --- a/dlls/wininet/cookie.c +++ b/dlls/wininet/cookie.c @@ -301,6 +301,14 @@ BOOL WINAPI InternetGetCookieW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName, } } } + + if (!domain_count) + { + TRACE("no cookies found for %s\n", debugstr_w(hostName)); + SetLastError(ERROR_NO_MORE_ITEMS); + return FALSE; + } + if (lpCookieData == NULL) { cnt += 1; /* NULL */ @@ -309,9 +317,6 @@ BOOL WINAPI InternetGetCookieW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName, return TRUE; } - if (!domain_count) - return FALSE; - *lpdwSize = (cnt + 1)*sizeof(WCHAR); TRACE("Returning %i (from %i domains): %s\n", cnt, domain_count, diff --git a/dlls/wininet/tests/internet.c b/dlls/wininet/tests/internet.c index aeeee4e4ce0..293656ccf46 100644 --- a/dlls/wininet/tests/internet.c +++ b/dlls/wininet/tests/internet.c @@ -27,7 +27,7 @@ #include "wine/test.h" -void InternetQueryOptionA_test() +static void InternetQueryOptionA_test(void) { HINTERNET hinet,hurl; DWORD len; @@ -107,7 +107,20 @@ void InternetQueryOptionA_test() InternetCloseHandle(hinet); } +static void test_get_cookie(void) +{ + DWORD len; + BOOL ret; + + SetLastError(0xdeadbeef); + ret = InternetGetCookie("http://www.example.com", NULL, NULL, &len); + ok(!ret && GetLastError() == ERROR_NO_MORE_ITEMS, + "InternetGetCookie should have failed with %s and error %ld\n", + ret ? "TRUE" : "FALSE", GetLastError()); +} + START_TEST(internet) { InternetQueryOptionA_test(); + test_get_cookie(); }