summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2020-01-17 11:28:57 +0100
committerDavid Lönnhager <david.l@mullvad.net>2020-01-17 12:46:13 +0100
commit9137a9d080d028f90e41fdd679b2105122357c00 (patch)
tree4eefd163e40b52526e63f4b8a100f4f9e8c38a7b
parenta7f29921f3341d5fe6c68785d1e4614feb254656 (diff)
downloadmullvadvpn-9137a9d080d028f90e41fdd679b2105122357c00.tar.xz
mullvadvpn-9137a9d080d028f90e41fdd679b2105122357c00.zip
Fix probable race condition in PATH update
-rw-r--r--dist-assets/windows/installer.nsh3
-rw-r--r--windows/nsis-plugins/src/pathedit/pathedit.cpp57
2 files changed, 52 insertions, 8 deletions
diff --git a/dist-assets/windows/installer.nsh b/dist-assets/windows/installer.nsh
index ede24932ab..74c4a7f050 100644
--- a/dist-assets/windows/installer.nsh
+++ b/dist-assets/windows/installer.nsh
@@ -850,10 +850,9 @@
${BreakInstallation}
Abort
${EndIf}
-
- ${InstallTrayIcon}
${AddCLIToEnvironPath}
+ ${InstallTrayIcon}
Pop $R0
diff --git a/windows/nsis-plugins/src/pathedit/pathedit.cpp b/windows/nsis-plugins/src/pathedit/pathedit.cpp
index 8b4e2b4b7e..ff01fa8a0f 100644
--- a/windows/nsis-plugins/src/pathedit/pathedit.cpp
+++ b/windows/nsis-plugins/src/pathedit/pathedit.cpp
@@ -22,8 +22,9 @@ using namespace common::registry;
using ValueStringType = RegistryKey::ValueStringType;
using common::string::Lower;
-static const wchar_t pathKeyName[] = L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";
-static const wchar_t pathValName[] = L"Path";
+static constexpr wchar_t pathKeyName[] = L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";
+static constexpr wchar_t pathValName[] = L"Path";
+static constexpr size_t messageTimeoutInterval = 5;
namespace
{
@@ -138,10 +139,32 @@ void __declspec(dllexport) NSISCALL AddSysEnvPath
pathRegKey->flush();
}
+ DWORD result;
THROW_GLE_IF(
- SendNotifyMessageW(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Environment"),
+ SendMessageTimeoutA(
+ HWND_BROADCAST,
+ WM_SETTINGCHANGE,
+ 0,
+ (LPARAM)"Environment",
+ SMTO_ABORTIFHUNG,
+ messageTimeoutInterval,
+ &result
+ ),
+ 0,
+ "SendMessageTimeoutA"
+ );
+ THROW_GLE_IF(
+ SendMessageTimeoutW(
+ HWND_BROADCAST,
+ WM_SETTINGCHANGE,
+ 0,
+ (LPARAM)L"Environment",
+ SMTO_ABORTIFHUNG,
+ messageTimeoutInterval,
+ &result
+ ),
0,
- "SendNotifyMessageW"
+ "SendMessageTimeoutW"
);
pushstring(L"");
@@ -211,10 +234,32 @@ void __declspec(dllexport) NSISCALL RemoveSysEnvPath
if (updatedPath)
{
+ DWORD result;
+ THROW_GLE_IF(
+ SendMessageTimeoutA(
+ HWND_BROADCAST,
+ WM_SETTINGCHANGE,
+ 0,
+ (LPARAM)"Environment",
+ SMTO_ABORTIFHUNG,
+ messageTimeoutInterval,
+ &result
+ ),
+ 0,
+ "SendMessageTimeoutA"
+ );
THROW_GLE_IF(
- SendNotifyMessageW(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)L"Environment"),
+ SendMessageTimeoutW(
+ HWND_BROADCAST,
+ WM_SETTINGCHANGE,
+ 0,
+ (LPARAM)L"Environment",
+ SMTO_ABORTIFHUNG,
+ messageTimeoutInterval,
+ &result
+ ),
0,
- "SendNotifyMessageW"
+ "SendMessageTimeoutW"
);
}