diff options
author | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2010-08-31 08:23:30 (GMT) |
---|---|---|
committer | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2010-09-03 08:22:25 (GMT) |
commit | 5738dcd705e7edde816940f9c0ab2c364c81ad20 (patch) | |
tree | e6be0a4b0f11289a7f0e8f6b4d4cce1de28aee8e /src/network/kernel | |
parent | dac9e5dd5644d29d6a8dde752e7c594727f16661 (diff) | |
download | Qt-5738dcd705e7edde816940f9c0ab2c364c81ad20.zip Qt-5738dcd705e7edde816940f9c0ab2c364c81ad20.tar.gz Qt-5738dcd705e7edde816940f9c0ab2c364c81ad20.tar.bz2 |
Ensure that we load system libraries from the correct location.
This was a security hole that has been there for a while, but the
public awareness have recently rised so the threat is more imminent
now.
The solution is to fix all places where we dynamically load system
libraries. More specifically, we now load all system libraries with
an absolute path that points to a library in the system directory
(usually c:\windows\system32).
We therefore introduce a small class named QSystemLibrary that only loads
libraries located in the system path. This shares some of the API with
QLibrary (in order to make the patch as small as possible).
We don't fix QLibrary due to risk of regressions. In
addition, applications can fix the code that calls QLibrary themselves.
The problem does not apply to Windows CE, since the search order is
documented as not searching in the current directory.
However, it touches some CE-specific code - therefore QSystemLibrary
is sometimes used on WinCE (however, it will just do a normal
LoadLibrary() since its safe anyway).
This change does not affect the testability plugin (it is not clearly
documented where that plugin is located, and the plugin should never
be used in production code anyway)
Loading OpenSSL libraries
The ssl libraries are handled specially, and searched in this order
(we cannot expect them to always be in the system folder):
1. Application path
2. System libraries path
3. Trying all paths inside the PATH environment variable
Task-number: QT-3825
Reviewed-by: Thiago Macieira
Reviewed-by: Peter Hartmann
Diffstat (limited to 'src/network/kernel')
-rw-r--r-- | src/network/kernel/qhostinfo_win.cpp | 14 | ||||
-rw-r--r-- | src/network/kernel/qnetworkinterface_win.cpp | 3 | ||||
-rw-r--r-- | src/network/kernel/qnetworkproxy_win.cpp | 15 |
3 files changed, 17 insertions, 15 deletions
diff --git a/src/network/kernel/qhostinfo_win.cpp b/src/network/kernel/qhostinfo_win.cpp index b30204b..8241c84 100644 --- a/src/network/kernel/qhostinfo_win.cpp +++ b/src/network/kernel/qhostinfo_win.cpp @@ -49,7 +49,7 @@ #include "qhostinfo_p.h" #include "private/qnativesocketengine_p.h" #include <ws2tcpip.h> -#include <qlibrary.h> +#include <private/qsystemlibrary_p.h> #include <qmutex.h> #include <qurl.h> #include <private/qmutexpool_p.h> @@ -90,13 +90,13 @@ static void resolveLibrary() // Attempt to resolve getaddrinfo(); without it we'll have to fall // back to gethostbyname(), which has no IPv6 support. #if !defined(Q_OS_WINCE) - local_getaddrinfo = (getaddrinfoProto) QLibrary::resolve(QLatin1String("ws2_32.dll"), "getaddrinfo"); - local_freeaddrinfo = (freeaddrinfoProto) QLibrary::resolve(QLatin1String("ws2_32.dll"), "freeaddrinfo"); - local_getnameinfo = (getnameinfoProto) QLibrary::resolve(QLatin1String("ws2_32.dll"), "getnameinfo"); + local_getaddrinfo = (getaddrinfoProto) QSystemLibrary::resolve(QLatin1String("ws2_32"), "getaddrinfo"); + local_freeaddrinfo = (freeaddrinfoProto) QSystemLibrary::resolve(QLatin1String("ws2_32"), "freeaddrinfo"); + local_getnameinfo = (getnameinfoProto) QSystemLibrary::resolve(QLatin1String("ws2_32"), "getnameinfo"); #else - local_getaddrinfo = (getaddrinfoProto) QLibrary::resolve(QLatin1String("ws2.dll"), "getaddrinfo"); - local_freeaddrinfo = (freeaddrinfoProto) QLibrary::resolve(QLatin1String("ws2.dll"), "freeaddrinfo"); - local_getnameinfo = (getnameinfoProto) QLibrary::resolve(QLatin1String("ws2.dll"), "getnameinfo"); + local_getaddrinfo = (getaddrinfoProto) QSystemLibrary::resolve(QLatin1String("ws2"), "getaddrinfo"); + local_freeaddrinfo = (freeaddrinfoProto) QSystemLibrary::resolve(QLatin1String("ws2"), "freeaddrinfo"); + local_getnameinfo = (getnameinfoProto) QSystemLibrary::resolve(QLatin1String("ws2"), "getnameinfo"); #endif } diff --git a/src/network/kernel/qnetworkinterface_win.cpp b/src/network/kernel/qnetworkinterface_win.cpp index 056650d..a1d1df6 100644 --- a/src/network/kernel/qnetworkinterface_win.cpp +++ b/src/network/kernel/qnetworkinterface_win.cpp @@ -48,6 +48,7 @@ #include <qhostinfo.h> #include <qhash.h> #include <qurl.h> +#include <private/qsystemlibrary_p.h> QT_BEGIN_NAMESPACE @@ -66,7 +67,7 @@ static void resolveLibs() if (!done) { done = true; - HINSTANCE iphlpapiHnd = LoadLibrary(L"iphlpapi"); + HINSTANCE iphlpapiHnd = QSystemLibrary::load(L"iphlpapi"); if (iphlpapiHnd == NULL) return; diff --git a/src/network/kernel/qnetworkproxy_win.cpp b/src/network/kernel/qnetworkproxy_win.cpp index e801738..de7c245 100644 --- a/src/network/kernel/qnetworkproxy_win.cpp +++ b/src/network/kernel/qnetworkproxy_win.cpp @@ -51,6 +51,7 @@ #include <string.h> #include <qt_windows.h> #include <wininet.h> +#include <private/qsystemlibrary_p.h> /* * Information on the WinHTTP DLL: @@ -273,15 +274,15 @@ void QWindowsSystemProxy::init() return; #else // load the winhttp.dll library - HINSTANCE winhttpHnd = LoadLibrary(L"winhttp"); - if (!winhttpHnd) + QSystemLibrary lib(L"winhttp"); + if (!lib.load()) return; // failed to load - ptrWinHttpOpen = (PtrWinHttpOpen)GetProcAddress(winhttpHnd, "WinHttpOpen"); - ptrWinHttpCloseHandle = (PtrWinHttpCloseHandle)GetProcAddress(winhttpHnd, "WinHttpCloseHandle"); - ptrWinHttpGetProxyForUrl = (PtrWinHttpGetProxyForUrl)GetProcAddress(winhttpHnd, "WinHttpGetProxyForUrl"); - ptrWinHttpGetDefaultProxyConfiguration = (PtrWinHttpGetDefaultProxyConfiguration)GetProcAddress(winhttpHnd, "WinHttpGetDefaultProxyConfiguration"); - ptrWinHttpGetIEProxyConfigForCurrentUser = (PtrWinHttpGetIEProxyConfigForCurrentUser)GetProcAddress(winhttpHnd, "WinHttpGetIEProxyConfigForCurrentUser"); + ptrWinHttpOpen = (PtrWinHttpOpen)lib.resolve("WinHttpOpen"); + ptrWinHttpCloseHandle = (PtrWinHttpCloseHandle)lib.resolve("WinHttpCloseHandle"); + ptrWinHttpGetProxyForUrl = (PtrWinHttpGetProxyForUrl)lib.resolve("WinHttpGetProxyForUrl"); + ptrWinHttpGetDefaultProxyConfiguration = (PtrWinHttpGetDefaultProxyConfiguration)lib.resolve("WinHttpGetDefaultProxyConfiguration"); + ptrWinHttpGetIEProxyConfigForCurrentUser = (PtrWinHttpGetIEProxyConfigForCurrentUser)lib.resolve("WinHttpGetIEProxyConfigForCurrentUser"); // Try to obtain the Internet Explorer configuration. WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ieProxyConfig; |