summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2012-06-08 16:54:18 +0200
committerMichael Meeks <michael.meeks@suse.com>2012-06-12 10:14:57 +0100
commita1555ee046fcf1fe9e49e8b6820316a66046698a (patch)
tree7fc05bd44a514961a7a1fba8e5853ca931a6e8e4
parent9ee04b49642b90d36aa51d5611d0def8f7c0516e (diff)
fdo#47044: Adapt to different Windows versions' InternetQueryOption behavior
Change-Id: Ia4d1d8f903872e5eefae2d9687866243b9055a13 (cherry picked from commit 0dded0d18a5945ed5a38623068ba7aa93da39df0) Conflicts: shell/source/backends/wininetbe/wininetbackend.cxx Signed-off-by: Michael Meeks <michael.meeks@suse.com>
-rwxr-xr-x[-rw-r--r--]shell/source/backends/wininetbe/wininetbackend.cxx66
1 files changed, 44 insertions, 22 deletions
diff --git a/shell/source/backends/wininetbe/wininetbackend.cxx b/shell/source/backends/wininetbe/wininetbackend.cxx
index 20d35c787b00..56866899d783 100644..100755
--- a/shell/source/backends/wininetbe/wininetbackend.cxx
+++ b/shell/source/backends/wininetbe/wininetbackend.cxx
@@ -123,32 +123,54 @@ WinInetBackend::WinInetBackend()
GetProcAddress( hWinInetDll.module, "InternetQueryOptionA" ) );
if (lpfnInternetQueryOption)
{
- LPINTERNET_PROXY_INFO lpi = NULL;
-
- // query for the neccessary space
- DWORD dwLength = 0;
- BOOL bRet = lpfnInternetQueryOption(
- NULL,
- INTERNET_OPTION_PROXY,
- (LPVOID)lpi,
- &dwLength );
-
- // allocate sufficient space on the heap
- // insufficient space on the heap results
- // in a stack overflow exception, we assume
- // this never happens, because of the relatively
- // small amount of memory we need
- // alloca is nice because it is fast and we don't
- // have to free the allocated memory, it will be
- // automatically done
- lpi = reinterpret_cast< LPINTERNET_PROXY_INFO >(
- alloca( dwLength ) );
-
- bRet = lpfnInternetQueryOption(
+ // Some Windows versions would fail the InternetQueryOption call
+ // with ERROR_OUTOFMEMORY when the initial dwLength were zero (and
+ // are apparently fine with the initial sizeof (INTERNET_PROXY_INFO)
+ // and need no reallocation), while other versions fail with
+ // ERROR_INSUFFICIENT_BUFFER upon that initial dwLength and need a
+ // reallocation:
+ INTERNET_PROXY_INFO pi;
+ LPINTERNET_PROXY_INFO lpi = &pi;
+ DWORD dwLength = sizeof (INTERNET_PROXY_INFO);
+ BOOL ok = lpfnInternetQueryOption(
NULL,
INTERNET_OPTION_PROXY,
(LPVOID)lpi,
&dwLength );
+ if (!ok)
+ {
+ DWORD err = GetLastError();
+ if (err = ERROR_INSUFFICIENT_BUFFER)
+ {
+ // allocate sufficient space on the heap
+ // insufficient space on the heap results
+ // in a stack overflow exception, we assume
+ // this never happens, because of the relatively
+ // small amount of memory we need
+ // alloca is nice because it is fast and we don't
+ // have to free the allocated memory, it will be
+ // automatically done
+ lpi = reinterpret_cast< LPINTERNET_PROXY_INFO >(
+ alloca( dwLength ) );
+ ok = lpfnInternetQueryOption(
+ NULL,
+ INTERNET_OPTION_PROXY,
+ (LPVOID)lpi,
+ &dwLength );
+ if (!ok)
+ {
+ err = GetLastError();
+ }
+ }
+ if (!ok)
+ {
+ SAL_WARN(
+ "shell",
+ "InternetQueryOption INTERNET_OPTION_PROXY"
+ " GetLastError=" << err);
+ return;
+ }
+ }
// if a proxy is disabled, InternetQueryOption returns
// an empty proxy list, so we don't have to check if