shell/source/backends/wininetbe/wininetbackend.cxx | 66 ++++++++++++++------- 1 file changed, 44 insertions(+), 22 deletions(-)
New commits: commit 0dded0d18a5945ed5a38623068ba7aa93da39df0 Author: Stephan Bergmann <sberg...@redhat.com> Date: Fri Jun 8 16:54:18 2012 +0200 fdo#47044: Adapt to different Windows versions' InternetQueryOption behavior Change-Id: Ia4d1d8f903872e5eefae2d9687866243b9055a13 diff --git a/shell/source/backends/wininetbe/wininetbackend.cxx b/shell/source/backends/wininetbe/wininetbackend.cxx old mode 100644 new mode 100755 index 4f364f7..ac6829e --- 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 _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits