Robert Shearman : wininet: Fix InternetGetCookie with no matching cookies.

Alexandre Julliard julliard at wine.codeweavers.com
Thu Mar 9 16:06:18 CST 2006


Module: wine
Branch: refs/heads/master
Commit: 1b8f7f06058b534e471be0df1763766c8185bf8b
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=1b8f7f06058b534e471be0df1763766c8185bf8b

Author: Robert Shearman <rob at codeweavers.com>
Date:   Thu Mar  9 15:20:24 2006 +0000

wininet: Fix InternetGetCookie with no matching cookies.

Return FALSE and an error of ERROR_NO_MORE_ITEMS from
InternetGetCookie when there are no cookies for the specified
domain. This fixes a bug in sending a blank cookie to HTTP servers.

---

 dlls/wininet/cookie.c         |   11 ++++++++---
 dlls/wininet/tests/internet.c |   15 ++++++++++++++-
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/dlls/wininet/cookie.c b/dlls/wininet/cookie.c
index 80bd8ea..043de1b 100644
--- a/dlls/wininet/cookie.c
+++ b/dlls/wininet/cookie.c
@@ -301,6 +301,14 @@ BOOL WINAPI InternetGetCookieW(LPCWSTR l
             }
         }
     }
+
+    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 l
 	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 aeeee4e..293656c 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();
 }




More information about the wine-cvs mailing list