From 2e0921d065121fe4bf3b17a54ab529f3fd4041fd Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Tue, 17 Jun 2014 02:57:10 +0200 Subject: [PATCH] wininet: Don't update *lpdwIndex if HttpQueryInfoW fails with ERROR_INSUFFICIENT_BUFFER. --- dlls/wininet/http.c | 3 +-- dlls/wininet/tests/http.c | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index c7e3474b9a5..d2b3de9b12b 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -3695,8 +3695,6 @@ static DWORD HTTP_HttpQueryInfoW(http_request_t *request, DWORD dwInfoLevel, return ERROR_HTTP_HEADER_NOT_FOUND; } - if (lpdwIndex) (*lpdwIndex)++; - /* coalesce value to requested type */ if (dwInfoLevel & HTTP_QUERY_FLAG_NUMBER && lpBuffer) { @@ -3742,6 +3740,7 @@ static DWORD HTTP_HttpQueryInfoW(http_request_t *request, DWORD dwInfoLevel, } *lpdwBufferLength = len - sizeof(WCHAR); } + if (lpdwIndex) (*lpdwIndex)++; return ERROR_SUCCESS; } diff --git a/dlls/wininet/tests/http.c b/dlls/wininet/tests/http.c index 41f4c5be0ae..f3340dfdf25 100644 --- a/dlls/wininet/tests/http.c +++ b/dlls/wininet/tests/http.c @@ -465,7 +465,7 @@ static void InternetReadFile_test(int flags, const test_data_t *test) char *post_data = NULL; BOOL res, on_async = TRUE; CHAR buffer[4000]; - DWORD length, exlen = 0, post_len = 0; + DWORD length, index, exlen = 0, post_len = 0; const char *types[2] = { "*", NULL }; HINTERNET hi, hic = 0, hor = 0; @@ -635,12 +635,23 @@ static void InternetReadFile_test(int flags, const test_data_t *test) ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError()); ok(!strcmp(buffer, test->redirected_url), "Wrong URL %s\n", buffer); + index = 0; + length = 0; + SetLastError(0xdeadbeef); + ok(HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,NULL,&length,&index) == FALSE,"Query worked\n"); + if(test->flags & TESTF_COMPRESSED) + ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, + "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError()); + ok(index == 0, "Index was incremented\n"); + + index = 0; length = 16; - res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,0x0); + res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,&index); trace("Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%u)\n",res,buffer,GetLastError()); if(test->flags & TESTF_COMPRESSED) ok(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%u)\n", res, GetLastError()); + ok(!res || index == 1, "Index was not incremented although result is %x (index = %u)\n", res, index); length = 100; res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0); @@ -1594,6 +1605,8 @@ static void HttpHeaders_test(void) strcpy(buffer,"Warning"); ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index) == FALSE,"Query succeeded on a too small buffer\n"); + ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError()); + ok(index == 0, "Index was incremented\n"); ok(strcmp(buffer,"Warning")==0, "incorrect string was returned(%s)\n",buffer); /* string not touched */ ok(len == 6, "Invalid length (exp. 6, got %d)\n", len); /* unlike success, the length includes the NULL-terminator */