diff options
Diffstat (limited to 'shell/source')
-rwxr-xr-x[-rw-r--r--] | shell/source/backends/wininetbe/wininetbackend.cxx | 66 |
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 = π + 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 |