Module: wine Branch: master Commit: f76208879e073226a8c55dff9ed4d52497538840 URL: https://source.winehq.org/git/wine.git/?a=commit;h=f76208879e073226a8c55dff9...
Author: Jacek Caban jacek@codeweavers.com Date: Wed Sep 19 16:17:46 2018 +0200
winhttp: Modify index only if query_headers succeeded.
Signed-off-by: Jacek Caban jacek@codeweavers.com Signed-off-by: Hans Leidekker hans@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/winhttp/request.c | 3 +-- dlls/winhttp/tests/winhttp.c | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/dlls/winhttp/request.c b/dlls/winhttp/request.c index 80694da..72cebdd 100644 --- a/dlls/winhttp/request.c +++ b/dlls/winhttp/request.c @@ -766,7 +766,6 @@ static BOOL query_headers( request_t *request, DWORD level, LPCWSTR name, LPVOID set_last_error( ERROR_WINHTTP_HEADER_NOT_FOUND ); return FALSE; } - if (index) *index += 1; if (level & WINHTTP_QUERY_FLAG_NUMBER) { if (!buffer || sizeof(int) > *buflen) @@ -813,6 +812,7 @@ static BOOL query_headers( request_t *request, DWORD level, LPCWSTR name, LPVOID } *buflen = len; } + if (ret && index) *index += 1; return ret; }
@@ -902,7 +902,6 @@ static BOOL query_auth_schemes( request_t *request, DWORD level, LPDWORD support query_headers( request, level, NULL, NULL, &size, &index ); if (get_last_error() != ERROR_INSUFFICIENT_BUFFER) break;
- index--; if (!(buffer = heap_alloc( size ))) return FALSE; if (!query_headers( request, level, NULL, buffer, &size, &index )) { diff --git a/dlls/winhttp/tests/winhttp.c b/dlls/winhttp/tests/winhttp.c index 1c72c07..5f0935f 100644 --- a/dlls/winhttp/tests/winhttp.c +++ b/dlls/winhttp/tests/winhttp.c @@ -33,6 +33,7 @@ #include <httprequestid.h>
#include "wine/test.h" +#include "wine/heap.h"
DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
@@ -42,6 +43,22 @@ static const WCHAR test_winehq[] = {'t','e','s','t','.','w','i','n','e','h','q', static const WCHAR test_winehq_https[] = {'h','t','t','p','s',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',':','4','4','3',0}; static const WCHAR localhostW[] = {'l','o','c','a','l','h','o','s','t',0};
+static WCHAR *a2w(const char *str) +{ + int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0); + WCHAR *ret = heap_alloc(len * sizeof(WCHAR)); + MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len); + return ret; +} + +static int strcmp_wa(const WCHAR *str1, const char *stra) +{ + WCHAR *str2 = a2w(stra); + int r = lstrcmpW(str1, str2); + heap_free(str2); + return r; +} + static BOOL proxy_active(void) { WINHTTP_PROXY_INFO proxy_info; @@ -2736,9 +2753,12 @@ static void test_basic_authentication(int port) static void test_multi_authentication(int port) { static const WCHAR multiauthW[] = {'/','m','u','l','t','i','a','u','t','h',0}; + static const WCHAR www_authenticateW[] = + {'W','W','W','-','A','u','t','h','e','n','t','i','c','a','t','e',0}; static const WCHAR getW[] = {'G','E','T',0}; HINTERNET ses, con, req; - DWORD supported, first, target; + DWORD supported, first, target, size, index; + WCHAR buf[512]; BOOL ret;
ses = WinHttpOpen(test_useragent, WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0); @@ -2764,6 +2784,22 @@ static void test_multi_authentication(int port) ok(target == WINHTTP_AUTH_TARGET_SERVER, "got %x\n", target); ok(first == WINHTTP_AUTH_SCHEME_BASIC, "got %x\n", first);
+ index = 0; + size = sizeof(buf); + ret = WinHttpQueryHeaders(req, WINHTTP_QUERY_CUSTOM, www_authenticateW, buf, &size, &index); + ok(ret, "expected success\n"); + ok(!strcmp_wa(buf, "Bearer"), "buf = %s\n", wine_dbgstr_w(buf)); + ok(size == lstrlenW(buf) * sizeof(WCHAR), "size = %u\n", size); + ok(index == 1, "index = %u\n", index); + + index = 0; + size = 0xdeadbeef; + ret = WinHttpQueryHeaders(req, WINHTTP_QUERY_CUSTOM, www_authenticateW, NULL, &size, &index); + ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, + "WinHttpQueryHeaders returned %x(%u)\n", ret, GetLastError()); + ok(size == (lstrlenW(buf) + 1) * sizeof(WCHAR), "size = %u\n", size); + ok(index == 0, "index = %u\n", index); + WinHttpCloseHandle(req); WinHttpCloseHandle(con); WinHttpCloseHandle(ses); @@ -3087,6 +3123,7 @@ static void test_bad_header( int port ) content_typeW, buffer, &len, &index ); ok( ret, "failed to query headers %u\n", GetLastError() ); ok( !lstrcmpW( buffer, text_htmlW ), "got %s\n", wine_dbgstr_w(buffer) ); + ok( index == 1, "index = %u\n", index );
WinHttpCloseHandle( req ); WinHttpCloseHandle( con );