Skip to content

Commit

Permalink
Prevent infinite loop during proxy authentication (#986)
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorlacey-msft authored and BillyONeal committed Dec 4, 2018
1 parent 7368961 commit 744f33b
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions Release/src/http/client/http_client_winhttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1723,23 +1723,27 @@ class winhttp_client final : public _http_client_communicator
}
}

static utility::string_t get_request_url(HINTERNET hRequestHandle)
static std::wstring get_request_url(HINTERNET hRequestHandle)
{
DWORD urlSize{ 0 };
if(FALSE == WinHttpQueryOption(hRequestHandle, WINHTTP_OPTION_URL, nullptr, &urlSize) || urlSize == 0)
std::wstring url;
auto urlSize = static_cast<unsigned long>(url.capacity()) * 2; // use initial small string optimization capacity
for (;;)
{
return U("");
}

auto urlwchar = new WCHAR[urlSize / sizeof(WCHAR)];

WinHttpQueryOption(hRequestHandle, WINHTTP_OPTION_URL, (void*)urlwchar, &urlSize);

utility::string_t url(urlwchar);

delete[] urlwchar;
url.resize(urlSize / sizeof(wchar_t));
if (WinHttpQueryOption(hRequestHandle, WINHTTP_OPTION_URL, &url[0], &urlSize))
{
url.resize(wcslen(url.c_str()));
return url;
}

return url;
const auto lastError = GetLastError();
if (lastError != ERROR_INSUFFICIENT_BUFFER || urlSize == 0)
{
url.clear();
url.shrink_to_fit();
return url;
}
}
}

// Returns true if we handle successfully and resending the request
Expand Down

0 comments on commit 744f33b

Please sign in to comment.