Skip to content

Commit 744f33b

Browse files
trevorlacey-msftBillyONeal
authored andcommitted
Prevent infinite loop during proxy authentication (#986)
1 parent 7368961 commit 744f33b

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

Release/src/http/client/http_client_winhttp.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,23 +1723,27 @@ class winhttp_client final : public _http_client_communicator
17231723
}
17241724
}
17251725

1726-
static utility::string_t get_request_url(HINTERNET hRequestHandle)
1726+
static std::wstring get_request_url(HINTERNET hRequestHandle)
17271727
{
1728-
DWORD urlSize{ 0 };
1729-
if(FALSE == WinHttpQueryOption(hRequestHandle, WINHTTP_OPTION_URL, nullptr, &urlSize) || urlSize == 0)
1728+
std::wstring url;
1729+
auto urlSize = static_cast<unsigned long>(url.capacity()) * 2; // use initial small string optimization capacity
1730+
for (;;)
17301731
{
1731-
return U("");
1732-
}
1733-
1734-
auto urlwchar = new WCHAR[urlSize / sizeof(WCHAR)];
1735-
1736-
WinHttpQueryOption(hRequestHandle, WINHTTP_OPTION_URL, (void*)urlwchar, &urlSize);
1737-
1738-
utility::string_t url(urlwchar);
1739-
1740-
delete[] urlwchar;
1732+
url.resize(urlSize / sizeof(wchar_t));
1733+
if (WinHttpQueryOption(hRequestHandle, WINHTTP_OPTION_URL, &url[0], &urlSize))
1734+
{
1735+
url.resize(wcslen(url.c_str()));
1736+
return url;
1737+
}
17411738

1742-
return url;
1739+
const auto lastError = GetLastError();
1740+
if (lastError != ERROR_INSUFFICIENT_BUFFER || urlSize == 0)
1741+
{
1742+
url.clear();
1743+
url.shrink_to_fit();
1744+
return url;
1745+
}
1746+
}
17431747
}
17441748

17451749
// Returns true if we handle successfully and resending the request

0 commit comments

Comments
 (0)