VeraCrypt
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2019-02-10 21:30:50 (GMT)
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2019-02-10 21:54:37 (GMT)
commit3903fcc595cbdcd403fa6713e663cf542e99c814 (patch)
treeb98681d570501d14508a1307b4a31a6d1beb2c92
parent97ccbaf0a36f6a8a82c7407746899a9fade34831 (diff)
downloadVeraCrypt-3903fcc595cbdcd403fa6713e663cf542e99c814.zip
VeraCrypt-3903fcc595cbdcd403fa6713e663cf542e99c814.tar.gz
Windows: Avoid simultaneous calls of favorites mounting, for example if corresponding hotkey is pressed multiple times.
-rw-r--r--src/Mount/Mount.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/Mount/Mount.c b/src/Mount/Mount.c
index 9873221..9cd6175 100644
--- a/src/Mount/Mount.c
+++ b/src/Mount/Mount.c
@@ -53,6 +53,9 @@
#include <Strsafe.h>
#include <InitGuid.h>
#include <devguid.h>
+#include <intrin.h>
+
+#pragma intrinsic(_InterlockedCompareExchange, _InterlockedExchange)
#import <msxml6.dll> no_auto_exclude
@@ -168,6 +171,8 @@ static MOUNT_LIST_STRUCT LastKnownMountList = {0};
VOLUME_NOTIFICATIONS_LIST VolumeNotificationsList;
static DWORD LastKnownLogicalDrives;
+static volatile LONG FavoriteMountOnGoing = 0;
+
static HANDLE TaskBarIconMutex = NULL;
static BOOL MainWindowHidden = FALSE;
static int pwdChangeDlgMode = PCDM_CHANGE_PASSWORD;
@@ -8626,7 +8631,8 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (lw == IDM_MOUNT_FAVORITE_VOLUMES)
{
- _beginthread(mountFavoriteVolumeThreadFunction, 0, NULL);
+ if (0 == _InterlockedCompareExchange(&FavoriteMountOnGoing, 1, 0))
+ _beginthread(mountFavoriteVolumeThreadFunction, 0, NULL);
return 1;
}
@@ -8707,13 +8713,16 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
}
else
{
- mountFavoriteVolumeThreadParam* pParam = (mountFavoriteVolumeThreadParam*) calloc(1, sizeof(mountFavoriteVolumeThreadParam));
- pParam->systemFavorites = FALSE;
- pParam->logOnMount = FALSE;
- pParam->hotKeyMount = FALSE;
- pParam->favoriteVolumeToMount = &FavoriteVolumes[favoriteIndex];
+ if (0 == _InterlockedCompareExchange(&FavoriteMountOnGoing, 1, 0))
+ {
+ mountFavoriteVolumeThreadParam* pParam = (mountFavoriteVolumeThreadParam*) calloc(1, sizeof(mountFavoriteVolumeThreadParam));
+ pParam->systemFavorites = FALSE;
+ pParam->logOnMount = FALSE;
+ pParam->hotKeyMount = FALSE;
+ pParam->favoriteVolumeToMount = &FavoriteVolumes[favoriteIndex];
- _beginthread(mountFavoriteVolumeThreadFunction, 0, pParam);
+ _beginthread(mountFavoriteVolumeThreadFunction, 0, pParam);
+ }
}
}
@@ -10168,6 +10177,7 @@ void CALLBACK mountFavoriteVolumeCallbackFunction (void *pArg, HWND hwnd)
void __cdecl mountFavoriteVolumeThreadFunction (void *pArg)
{
ShowWaitDialog (MainDlg, FALSE, mountFavoriteVolumeCallbackFunction, pArg);
+ _InterlockedExchange(&FavoriteMountOnGoing, 0);
}
static void SaveDefaultKeyFilesParam (HWND hwnd)
@@ -10302,13 +10312,16 @@ static void HandleHotKey (HWND hwndDlg, WPARAM wParam)
case HK_MOUNT_FAVORITE_VOLUMES:
{
- mountFavoriteVolumeThreadParam* pParam = (mountFavoriteVolumeThreadParam*) calloc(1, sizeof(mountFavoriteVolumeThreadParam));
- pParam->systemFavorites = FALSE;
- pParam->logOnMount = FALSE;
- pParam->hotKeyMount = TRUE;
- pParam->favoriteVolumeToMount = NULL;
+ if (0 == _InterlockedCompareExchange(&FavoriteMountOnGoing, 1, 0))
+ {
+ mountFavoriteVolumeThreadParam* pParam = (mountFavoriteVolumeThreadParam*) calloc(1, sizeof(mountFavoriteVolumeThreadParam));
+ pParam->systemFavorites = FALSE;
+ pParam->logOnMount = FALSE;
+ pParam->hotKeyMount = TRUE;
+ pParam->favoriteVolumeToMount = NULL;
- _beginthread(mountFavoriteVolumeThreadFunction, 0, pParam);
+ _beginthread(mountFavoriteVolumeThreadFunction, 0, pParam);
+ }
}
break;