From 8272f5415b1ac89fd169513160870ab85bbf1bef Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 24 Apr 2015 10:47:29 +0200 Subject: Fix crashes when accessing environment variables concurrently MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We've seen crashes with QThreadPrivate::start using qgetenv during the creation of the event dispatcher, while another thread (for example the gui thread) called qputenv. This is inherently thread-unsafe and there are many places where we make the assumption that using the environment is safe. However access to the environment is inherently unsafe in the C runtime and the best that we can do is add a mutex around the Qt environment access functions, to at least protect ourselves and our users. Change-Id: Ie9a718d9f7ce63c423c645f0be3e3f4933e1cb08 Reviewed-by: Marc Mutz Reviewed-by: Jørgen Lind --- src/corelib/io/qsettings.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/corelib/io/qsettings.cpp') diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index afe68125d4..cb6de29532 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -1048,12 +1048,12 @@ static void initDefaultPaths(QMutexLocker *locker) // Non XDG platforms (OS X, iOS, Blackberry, Android...) have used this code path erroneously // for some time now. Moving away from that would require migrating existing settings. QString userPath; - char *env = getenv("XDG_CONFIG_HOME"); - if (env == 0) { + QByteArray env = qgetenv("XDG_CONFIG_HOME"); + if (env.isEmpty()) { userPath = QDir::homePath(); userPath += QLatin1Char('/'); userPath += QLatin1String(".config"); - } else if (*env == '/') { + } else if (env.startsWith('/')) { userPath = QFile::decodeName(env); } else { userPath = QDir::homePath(); -- cgit v1.2.3