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/ssl/qsslsocket_openssl_symbols.cpp | |
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/ssl/qsslsocket_openssl_symbols.cpp')
-rw-r--r-- | src/network/ssl/qsslsocket_openssl_symbols.cpp | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/src/network/ssl/qsslsocket_openssl_symbols.cpp b/src/network/ssl/qsslsocket_openssl_symbols.cpp index 8620e00..9e550ae 100644 --- a/src/network/ssl/qsslsocket_openssl_symbols.cpp +++ b/src/network/ssl/qsslsocket_openssl_symbols.cpp @@ -42,7 +42,11 @@ #include "qsslsocket_openssl_symbols_p.h" -#include <QtCore/qlibrary.h> +#ifdef Q_OS_WIN +# include <private/qsystemlibrary_p.h> +#else +# include <QtCore/qlibrary.h> +#endif #include <QtCore/qmutex.h> #include <private/qmutexpool_p.h> #include <QtCore/qdatetime.h> @@ -343,22 +347,22 @@ static QStringList findAllLibSsl() } # endif -static QPair<QLibrary*, QLibrary*> loadOpenSsl() +#ifdef Q_OS_WIN +static QPair<QSystemLibrary*, QSystemLibrary*> loadOpenSslWin32() { - QPair<QLibrary*,QLibrary*> pair; + QPair<QSystemLibrary*,QSystemLibrary*> pair; pair.first = 0; pair.second = 0; -# ifdef Q_OS_WIN - QLibrary *ssleay32 = new QLibrary(QLatin1String("ssleay32")); - if (!ssleay32->load()) { + QSystemLibrary *ssleay32 = new QSystemLibrary(QLatin1String("ssleay32")); + if (!ssleay32->load(false)) { // Cannot find ssleay32.dll delete ssleay32; return pair; } - QLibrary *libeay32 = new QLibrary(QLatin1String("libeay32")); - if (!libeay32->load()) { + QSystemLibrary *libeay32 = new QSystemLibrary(QLatin1String("libeay32")); + if (!libeay32->load(false)) { delete ssleay32; delete libeay32; return pair; @@ -367,7 +371,16 @@ static QPair<QLibrary*, QLibrary*> loadOpenSsl() pair.first = ssleay32; pair.second = libeay32; return pair; -# elif defined(Q_OS_SYMBIAN) +} +#else + +static QPair<QLibrary*, QLibrary*> loadOpenSsl() +{ + QPair<QLibrary*,QLibrary*> pair; + pair.first = 0; + pair.second = 0; + +# if defined(Q_OS_SYMBIAN) QLibrary *libssl = new QLibrary(QLatin1String("libssl")); if (!libssl->load()) { // Cannot find ssleay32.dll @@ -467,6 +480,7 @@ static QPair<QLibrary*, QLibrary*> loadOpenSsl() return pair; # endif } +#endif bool q_resolveOpenSslSymbols() { @@ -481,7 +495,11 @@ bool q_resolveOpenSslSymbols() return false; triedToResolveSymbols = true; +#ifdef Q_OS_WIN + QPair<QSystemLibrary *, QSystemLibrary *> libs = loadOpenSslWin32(); +#else QPair<QLibrary *, QLibrary *> libs = loadOpenSsl(); +#endif if (!libs.first || !libs.second) // failed to load them return false; |