From fbc99515eb905094dd5d4d0f48eda0ecb752b4c8 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Fri, 24 Apr 2009 14:59:08 +0200 Subject: [PATCH] wininet: Fix parsing of cookies with attributes. --- dlls/wininet/cookie.c | 26 +++++++++++++++++++++----- dlls/wininet/tests/internet.c | 9 +++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/dlls/wininet/cookie.c b/dlls/wininet/cookie.c index fdccd657210..dc77b17265b 100644 --- a/dlls/wininet/cookie.c +++ b/dlls/wininet/cookie.c @@ -447,12 +447,12 @@ static BOOL set_cookie(LPCWSTR domain, LPCWSTR path, LPCWSTR cookie_name, LPCWST cookie_domain *thisCookieDomain = NULL; cookie *thisCookie; struct list *cursor; - LPWSTR data; + LPWSTR data, value; WCHAR *ptr; FILETIME expiry; BOOL expired = FALSE; - data = HeapAlloc(GetProcessHeap(),0,(lstrlenW(cookie_data)+1) * sizeof(WCHAR)); + value = data = HeapAlloc(GetProcessHeap(), 0, (strlenW(cookie_data) + 1) * sizeof(WCHAR)); strcpyW(data,cookie_data); memset(&expiry,0,sizeof(expiry)); @@ -469,6 +469,10 @@ static BOOL set_cookie(LPCWSTR domain, LPCWSTR path, LPCWSTR cookie_name, LPCWST if (!(ptr = strchrW(ptr,';'))) break; *ptr++ = 0; + + value = HeapAlloc(GetProcessHeap(), 0, (ptr - data) * sizeof(WCHAR)); + strcpyW(value, data); + while (*ptr == ' ') ptr++; /* whitespace */ if (strncmpiW(ptr, szDomain, 7) == 0) @@ -502,11 +506,20 @@ static BOOL set_cookie(LPCWSTR domain, LPCWSTR path, LPCWSTR cookie_name, LPCWST } } else if (strncmpiW(ptr, szSecure, 6) == 0) + { FIXME("secure not handled (%s)\n",debugstr_w(ptr)); + ptr += strlenW(szSecure); + } else if (strncmpiW(ptr, szHttpOnly, 8) == 0) + { FIXME("httponly not handled (%s)\n",debugstr_w(ptr)); - else + ptr += strlenW(szHttpOnly); + } + else if (*ptr) + { FIXME("Unknown additional option %s\n",debugstr_w(ptr)); + break; + } } LIST_FOR_EACH(cursor, &domain_list) @@ -524,6 +537,7 @@ static BOOL set_cookie(LPCWSTR domain, LPCWSTR path, LPCWSTR cookie_name, LPCWST else { HeapFree(GetProcessHeap(),0,data); + if (value != data) HeapFree(GetProcessHeap(), 0, value); return TRUE; } } @@ -532,15 +546,17 @@ static BOOL set_cookie(LPCWSTR domain, LPCWSTR path, LPCWSTR cookie_name, LPCWST COOKIE_deleteCookie(thisCookie, FALSE); TRACE("setting cookie %s=%s for domain %s path %s\n", debugstr_w(cookie_name), - debugstr_w(data), debugstr_w(thisCookieDomain->lpCookieDomain),debugstr_w(thisCookieDomain->lpCookiePath)); + debugstr_w(value), debugstr_w(thisCookieDomain->lpCookieDomain),debugstr_w(thisCookieDomain->lpCookiePath)); - if (!expired && !COOKIE_addCookie(thisCookieDomain, cookie_name,data, expiry)) + if (!expired && !COOKIE_addCookie(thisCookieDomain, cookie_name, value, expiry)) { HeapFree(GetProcessHeap(),0,data); + if (value != data) HeapFree(GetProcessHeap(), 0, value); return FALSE; } HeapFree(GetProcessHeap(),0,data); + if (value != data) HeapFree(GetProcessHeap(), 0, value); return TRUE; } diff --git a/dlls/wininet/tests/internet.c b/dlls/wininet/tests/internet.c index 0ec7242ba17..3c1b3da9c41 100644 --- a/dlls/wininet/tests/internet.c +++ b/dlls/wininet/tests/internet.c @@ -272,6 +272,8 @@ static void test_complicated_cookie(void) ok(ret == TRUE,"InternetSetCookie failed\n"); ret = InternetSetCookie("http://www.example.com/bar/",NULL,"M=N; domain=.example.com; path=/foo/"); ok(ret == TRUE,"InternetSetCookie failed\n"); + ret = InternetSetCookie("http://www.example.com/bar/",NULL,"O=P; secure; path=/bar"); + ok(ret == TRUE,"InternetSetCookie failed\n"); len = 1024; ret = InternetGetCookie("http://testing.example.com", NULL, buffer, &len); @@ -282,6 +284,7 @@ static void test_complicated_cookie(void) ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n"); ok(strstr(buffer,"K=L")==NULL,"K=L present\n"); ok(strstr(buffer,"M=N")==NULL,"M=N present\n"); + ok(strstr(buffer,"O=P")==NULL,"O=P present\n"); len = 1024; ret = InternetGetCookie("http://testing.example.com/foobar", NULL, buffer, &len); @@ -292,6 +295,7 @@ static void test_complicated_cookie(void) ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n"); ok(strstr(buffer,"K=L")==NULL,"K=L present\n"); ok(strstr(buffer,"M=N")==NULL,"M=N present\n"); + ok(strstr(buffer,"O=P")==NULL,"O=P present\n"); len = 1024; ret = InternetGetCookie("http://testing.example.com/foobar/", NULL, buffer, &len); @@ -302,6 +306,7 @@ static void test_complicated_cookie(void) ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n"); ok(strstr(buffer,"K=L")==NULL,"K=L present\n"); ok(strstr(buffer,"M=N")==NULL,"M=N present\n"); + ok(strstr(buffer,"O=P")==NULL,"O=P present\n"); len = 1024; ret = InternetGetCookie("http://testing.example.com/foo/bar", NULL, buffer, &len); @@ -312,6 +317,7 @@ static void test_complicated_cookie(void) ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n"); ok(strstr(buffer,"K=L")==NULL,"K=L present\n"); ok(strstr(buffer,"M=N")!=NULL,"M=N missing\n"); + ok(strstr(buffer,"O=P")==NULL,"O=P present\n"); len = 1024; ret = InternetGetCookie("http://testing.example.com/barfoo", NULL, buffer, &len); @@ -322,6 +328,7 @@ static void test_complicated_cookie(void) ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n"); ok(strstr(buffer,"K=L")==NULL,"K=L present\n"); ok(strstr(buffer,"M=N")==NULL,"M=N present\n"); + ok(strstr(buffer,"O=P")==NULL,"O=P present\n"); len = 1024; ret = InternetGetCookie("http://testing.example.com/barfoo/", NULL, buffer, &len); @@ -332,6 +339,7 @@ static void test_complicated_cookie(void) ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n"); ok(strstr(buffer,"K=L")==NULL,"K=L present\n"); ok(strstr(buffer,"M=N")==NULL,"M=N present\n"); + ok(strstr(buffer,"O=P")==NULL,"O=P present\n"); len = 1024; ret = InternetGetCookie("http://testing.example.com/bar/foo", NULL, buffer, &len); @@ -342,6 +350,7 @@ static void test_complicated_cookie(void) ok(strstr(buffer,"I=J")!=NULL,"I=J missing\n"); ok(strstr(buffer,"K=L")!=NULL,"K=L missing\n"); ok(strstr(buffer,"M=N")==NULL,"M=N present\n"); + ok(strstr(buffer,"O=P")==NULL,"O=P present\n"); } static void test_null(void) -- 2.11.4.GIT