From aa27aac08b8c0a8501ad491171bba9108fd090bd Mon Sep 17 00:00:00 2001 From: winesync Date: Tue, 8 Dec 2020 18:22:04 +0100 Subject: [PATCH] [WINESYNC] wininet: Strip filename if no path is set in cookie. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The order of the stored cookies doesn't match in /testC, so be a bit less strict in the test. wine-staging patch by Michael Müller --- dll/win32/wininet/http.c | 11 ++- modules/rostests/winetests/wininet/http.c | 6 +- ..._filename_if_no_path_is_set_in_cookie.diff | 67 +++++++++++++++++++ 3 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 sdk/tools/winesync/wininet_staging/0004-wininet__Strip_filename_if_no_path_is_set_in_cookie.diff diff --git a/dll/win32/wininet/http.c b/dll/win32/wininet/http.c index 73c5a61dae4..28d48c1eb6b 100644 --- a/dll/win32/wininet/http.c +++ b/dll/win32/wininet/http.c @@ -668,10 +668,18 @@ static void HTTP_ProcessCookies( http_request_t *request ) int HeaderIndex; int numCookies = 0; LPHTTPHEADERW setCookieHeader; + WCHAR *path, *tmp; if(request->hdr.dwFlags & INTERNET_FLAG_NO_COOKIES) return; + path = heap_strdupW(request->path); + if (!path) + return; + + tmp = wcsrchr(path, '/'); + if (tmp && tmp[1]) tmp[1] = 0; + EnterCriticalSection( &request->headers_section ); while((HeaderIndex = HTTP_GetCustomHeaderIndex(request, L"Set-Cookie", numCookies++, FALSE)) != -1) @@ -690,10 +698,11 @@ static void HTTP_ProcessCookies( http_request_t *request ) name = substr(setCookieHeader->lpszValue, data - setCookieHeader->lpszValue); data++; - set_cookie(substrz(request->server->name), substrz(request->path), name, substrz(data), INTERNET_COOKIE_HTTPONLY); + set_cookie(substrz(request->server->name), substrz(path), name, substrz(data), INTERNET_COOKIE_HTTPONLY); } LeaveCriticalSection( &request->headers_section ); + heap_free(path); } static void strip_spaces(LPWSTR start) diff --git a/modules/rostests/winetests/wininet/http.c b/modules/rostests/winetests/wininet/http.c index ce2dfd477c3..3b7fd390556 100644 --- a/modules/rostests/winetests/wininet/http.c +++ b/modules/rostests/winetests/wininet/http.c @@ -2364,7 +2364,7 @@ static DWORD CALLBACK server_thread(LPVOID param) } if (strstr(buffer, "/testC")) { - if (strstr(buffer, "Cookie: cookie=biscuit")) + if (strstr(buffer, "cookie=biscuit")) send(c, okmsg, sizeof okmsg-1, 0); else send(c, notokmsg, sizeof notokmsg-1, 0); @@ -3352,7 +3352,7 @@ static void test_header_override(int port) ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n"); - test_status_code_todo(req, 200); + test_status_code(req, 200); InternetCloseHandle(req); req = HttpOpenRequestA(con, NULL, "/test_cookie_check_host_override", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0); @@ -3361,7 +3361,7 @@ static void test_header_override(int port) ret = HttpSendRequestA(req, NULL, 0, NULL, 0); ok(ret, "HttpSendRequest failed\n"); - test_status_code_todo(req, 200); + test_status_code(req, 200); InternetCloseHandle(req); InternetSetCookieA("http://test.local", "foo", "bar"); diff --git a/sdk/tools/winesync/wininet_staging/0004-wininet__Strip_filename_if_no_path_is_set_in_cookie.diff b/sdk/tools/winesync/wininet_staging/0004-wininet__Strip_filename_if_no_path_is_set_in_cookie.diff new file mode 100644 index 00000000000..b45c152a8db --- /dev/null +++ b/sdk/tools/winesync/wininet_staging/0004-wininet__Strip_filename_if_no_path_is_set_in_cookie.diff @@ -0,0 +1,67 @@ +diff --git a/dll/win32/wininet/http.c b/dll/win32/wininet/http.c +index c770c31..d95b39b 100644 +--- a/dll/win32/wininet/http.c ++++ b/dll/win32/wininet/http.c +@@ -654,10 +654,18 @@ static void HTTP_ProcessCookies( http_request_t *request ) + int HeaderIndex; + int numCookies = 0; + LPHTTPHEADERW setCookieHeader; ++ WCHAR *path, *tmp; + + if(request->hdr.dwFlags & INTERNET_FLAG_NO_COOKIES) + return; + ++ path = heap_strdupW(request->path); ++ if (!path) ++ return; ++ ++ tmp = wcsrchr(path, '/'); ++ if (tmp && tmp[1]) tmp[1] = 0; ++ + EnterCriticalSection( &request->headers_section ); + + while((HeaderIndex = HTTP_GetCustomHeaderIndex(request, L"Set-Cookie", numCookies++, FALSE)) != -1) +@@ -676,10 +684,11 @@ static void HTTP_ProcessCookies( http_request_t *request ) + + name = substr(setCookieHeader->lpszValue, data - setCookieHeader->lpszValue); + data++; +- set_cookie(substrz(request->server->name), substrz(request->path), name, substrz(data), INTERNET_COOKIE_HTTPONLY); ++ set_cookie(substrz(request->server->name), substrz(path), name, substrz(data), INTERNET_COOKIE_HTTPONLY); + } + + LeaveCriticalSection( &request->headers_section ); ++ heap_free(path); + } + + static void strip_spaces(LPWSTR start) +diff --git a/modules/rostests/winetests/wininet/http.c b/modules/rostests/winetests/wininet/http.c +index 510c3ac..b98e648 100644 +--- a/modules/rostests/winetests/wininet/http.c ++++ b/modules/rostests/winetests/wininet/http.c +@@ -2363,7 +2363,7 @@ static DWORD CALLBACK server_thread(LPVOID param) + } + if (strstr(buffer, "/testC")) + { +- if (strstr(buffer, "Cookie: cookie=biscuit")) ++ if (strstr(buffer, "cookie=biscuit")) + send(c, okmsg, sizeof okmsg-1, 0); + else + send(c, notokmsg, sizeof notokmsg-1, 0); +@@ -3351,7 +3351,7 @@ static void test_header_override(int port) + ret = HttpSendRequestA(req, NULL, 0, NULL, 0); + ok(ret, "HttpSendRequest failed\n"); + +- test_status_code_todo(req, 200); ++ test_status_code(req, 200); + + InternetCloseHandle(req); + req = HttpOpenRequestA(con, NULL, "/test_cookie_check_host_override", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0); +@@ -3360,7 +3360,7 @@ static void test_header_override(int port) + ret = HttpSendRequestA(req, NULL, 0, NULL, 0); + ok(ret, "HttpSendRequest failed\n"); + +- test_status_code_todo(req, 200); ++ test_status_code(req, 200); + + InternetCloseHandle(req); + InternetSetCookieA("http://test.local", "foo", "bar");