From 7d1e6ca1998f6fd26795b1f9e408ccd7c7c0b558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20L=C3=B6sch?= Date: Thu, 31 Mar 2016 15:09:20 +0200 Subject: Limit URLs for proxy auto config to 2083 chars On Windows only URLs up to 2083 characters are supported, so longer URLs are truncated. Task-number: QTBUG-52271 Change-Id: I625e4d089df4d977d39e61e5831611e04260e729 Reviewed-by: Markus Goetz (Woboq GmbH) --- src/network/kernel/qnetworkproxy_win.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/network/kernel/qnetworkproxy_win.cpp') diff --git a/src/network/kernel/qnetworkproxy_win.cpp b/src/network/kernel/qnetworkproxy_win.cpp index 9e571bfe7f..15ef7d7cee 100644 --- a/src/network/kernel/qnetworkproxy_win.cpp +++ b/src/network/kernel/qnetworkproxy_win.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -590,8 +591,16 @@ QList QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro url.setScheme(QLatin1String("https")); } + QString urlQueryString = url.toString(); + if (urlQueryString.size() > 2083) { + // calls to WinHttpGetProxyForUrl with urls longer than 2083 characters + // fail with error code ERROR_INVALID_PARAMETER(87), so we truncate it + qWarning("Proxy query URL too long for windows API, try with truncated URL"); + urlQueryString = url.toString().left(2083); + } + bool getProxySucceeded = ptrWinHttpGetProxyForUrl(sp->hHttpSession, - (LPCWSTR)url.toString().utf16(), + (LPCWSTR)urlQueryString.utf16(), &sp->autoProxyOptions, &proxyInfo); DWORD getProxyError = GetLastError(); @@ -608,7 +617,7 @@ QList QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro sp->autoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_CONFIG_URL; sp->autoProxyOptions.lpszAutoConfigUrl = (LPCWSTR)sp->autoConfigUrl.utf16(); getProxySucceeded = ptrWinHttpGetProxyForUrl(sp->hHttpSession, - (LPCWSTR)url.toString().utf16(), + (LPCWSTR)urlQueryString.utf16(), &sp->autoProxyOptions, &proxyInfo); getProxyError = GetLastError(); @@ -621,7 +630,7 @@ QList QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro // But now we've to enable it (http://msdn.microsoft.com/en-us/library/aa383153%28v=VS.85%29.aspx) sp->autoProxyOptions.fAutoLogonIfChallenged = TRUE; getProxySucceeded = ptrWinHttpGetProxyForUrl(sp->hHttpSession, - (LPCWSTR)url.toString().utf16(), + (LPCWSTR)urlQueryString.utf16(), &sp->autoProxyOptions, &proxyInfo); getProxyError = GetLastError(); -- cgit v1.2.3