summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2012-06-08 16:54:18 +0200
committerStephan Bergmann <sbergman@redhat.com>2012-06-08 16:54:18 +0200
commit0dded0d18a5945ed5a38623068ba7aa93da39df0 (patch)
treefa3bda7442d35ebe23579f5040eff7f144051323
parent106d638e6cd4dceffc0aa98a7772d69488ae0a39 (diff)
fdo#47044: Adapt to different Windows versions' InternetQueryOption behavior
Change-Id: Ia4d1d8f903872e5eefae2d9687866243b9055a13
-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 4f364f7246c0..ac6829e60c73 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;
- 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 ) );
-
- 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