From adff8071554f189d7aef099dae6500c55f6ad499 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Thu, 20 Apr 2017 21:58:37 +0200 Subject: [PATCH] Fixed possible race condition in ShellIntegration class. --- src/ShellIntegration.cpp | 18 +++++++++++------- src/ShellIntegration.h | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/ShellIntegration.cpp b/src/ShellIntegration.cpp index 6b256c85..f0e1c72b 100644 --- a/src/ShellIntegration.cpp +++ b/src/ShellIntegration.cpp @@ -79,9 +79,11 @@ void ShellIntegration::install(bool async) return; } + //Serialize + QMutexLocker lock(&m_mutex); + //Checking - const int originalState = m_state.fetchAndStoreOrdered(STATE_ENABLED); - if(originalState == STATE_ENABLED) + if(m_state.fetchAndStoreOrdered(STATE_ENABLED) == STATE_ENABLED) { return; /*already enabled, don't enable again!*/ } @@ -101,7 +103,7 @@ void ShellIntegration::install(bool async) ok[3] = MUtils::Registry::reg_value_write(MUtils::Registry::root_user, QString("Software\\Classes\\%1\\shell\\%2\\command").arg(lamexpFileType, lamexpShellAction), QString(), lamexpShellCommand); if(!(ok[0] && ok[1] && ok[2] && ok[3])) { - m_state.fetchAndStoreOrdered(originalState); + m_state.fetchAndStoreOrdered(STATE_UNKNOWN); qWarning("Failed to register the LameXP file type!"); return; } @@ -130,11 +132,13 @@ void ShellIntegration::remove(bool async) return; } + //Serialize + QMutexLocker lock(&m_mutex); + //Checking - const int originalState = m_state.fetchAndStoreOrdered(STATE_DISABLD); - if(originalState == STATE_DISABLD) + if(m_state.fetchAndStoreOrdered(STATE_DISABLD) == STATE_DISABLD) { - return; /*already enabled, don't enable again!*/ + return; /*already disabled, don't disable again!*/ } //Init some consts @@ -147,7 +151,7 @@ void ShellIntegration::remove(bool async) //Find all registered file types if(!MUtils::Registry::reg_enum_subkeys(MUtils::Registry::root_user, "Software\\Classes", fileTypes)) { - m_state.fetchAndStoreOrdered(originalState); + m_state.fetchAndStoreOrdered(STATE_UNKNOWN); qWarning("Failed to enumerate file types!"); return; } diff --git a/src/ShellIntegration.h b/src/ShellIntegration.h index 2e77c21a..856bd90b 100644 --- a/src/ShellIntegration.h +++ b/src/ShellIntegration.h @@ -40,5 +40,6 @@ private: ShellIntegration(void); static void initializeTypes(const QString &lamexpFileType, const QString &lamexpShellAction, QStringList &nativeTypes); + static QMutex m_mutex; static QAtomicInt m_state; }; -- 2.11.4.GIT