From c1d670fd752b96abac09b919d7ca1bff4ebafcbc Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Mon, 10 Feb 2020 00:21:15 +0100 Subject: Windows: Fix warnings reported by Coverity static code analyzer --- src/Common/Dlgcode.c | 11 +++++++---- src/ExpandVolume/ExpandVolume.c | 11 ++++++----- src/Format/InPlace.c | 25 +++++++++++++++++-------- src/Mount/Mount.c | 7 +++++++ 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c index 7640b59e..5a2ed526 100644 --- a/src/Common/Dlgcode.c +++ b/src/Common/Dlgcode.c @@ -5529,11 +5529,11 @@ static void DisplayBenchmarkResults (HWND hwndDlg) SendMessageW (hList, LVM_SETITEMW, 0, (LPARAM)&LvItem); break; case BENCHMARK_TYPE_PRF: - swprintf_s (item1, sizeof(item1) / sizeof(item1[0]), L"%d ms", benchmarkTable[i].meanBytesPerSec); + swprintf_s (item1, sizeof(item1) / sizeof(item1[0]), L"%d ms", (int) benchmarkTable[i].meanBytesPerSec); LvItem.iSubItem = 1; LvItem.pszText = item1; SendMessageW (hList, LVM_SETITEMW, 0, (LPARAM)&LvItem); - swprintf_s (item1, sizeof(item1) / sizeof(item1[0]), L"%d", benchmarkTable[i].decSpeed); + swprintf_s (item1, sizeof(item1) / sizeof(item1[0]), L"%d", (int) benchmarkTable[i].decSpeed); LvItem.iSubItem = 2; LvItem.pszText = item1; SendMessageW (hList, LVM_SETITEMW, 0, (LPARAM)&LvItem); @@ -7530,7 +7530,10 @@ int GetLastAvailableDrive () BOOL IsDriveAvailable (int driveNo) { - return (GetUsedLogicalDrives() & (1 << driveNo)) == 0; + if (driveNo >= 0 && driveNo < 26) + return (GetUsedLogicalDrives() & (1 << driveNo)) == 0; + else + return FALSE; } @@ -13057,7 +13060,7 @@ BOOL IsApplicationInstalled (const wchar_t *appName, BOOL b32bitApp) } wchar_t regName[1024]; - DWORD regNameSize = sizeof (regName); + DWORD regNameSize = ARRAYSIZE (regName); DWORD index = 0; while (RegEnumKeyEx (unistallKey, index++, regName, ®NameSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { diff --git a/src/ExpandVolume/ExpandVolume.c b/src/ExpandVolume/ExpandVolume.c index 73878bbb..e340a8bb 100644 --- a/src/ExpandVolume/ExpandVolume.c +++ b/src/ExpandVolume/ExpandVolume.c @@ -515,6 +515,7 @@ static int ExpandVolume (HWND hwndDlg, wchar_t *lpszVolume, Password *pVolumePas #ifdef _WIN64 CRYPTO_INFO tmpCI; PCRYPTO_INFO cryptoInfoBackup = NULL; + BOOL bIsRamEncryptionEnabled = IsRamEncryptionEnabled(); #endif if (pVolumePassword->Length == 0) return -1; @@ -684,7 +685,7 @@ static int ExpandVolume (HWND hwndDlg, wchar_t *lpszVolume, Password *pVolumePas } #ifdef _WIN64 - if (IsRamEncryptionEnabled()) + if (bIsRamEncryptionEnabled) { VcProtectKeys (cryptoInfo, VcGetEncryptionID (cryptoInfo)); } @@ -856,7 +857,7 @@ static int ExpandVolume (HWND hwndDlg, wchar_t *lpszVolume, Password *pVolumePas DebugAddProgressDlgStatus(hwndDlg, L"Writing re-encrypted primary header ...\r\n"); #ifdef _WIN64 - if (IsRamEncryptionEnabled ()) + if (bIsRamEncryptionEnabled) { VirtualLock (&tmpCI, sizeof (CRYPTO_INFO)); memcpy (&tmpCI, cryptoInfo, sizeof (CRYPTO_INFO)); @@ -886,7 +887,7 @@ static int ExpandVolume (HWND hwndDlg, wchar_t *lpszVolume, Password *pVolumePas FALSE ); // use slow poll #ifdef _WIN64 - if (IsRamEncryptionEnabled ()) + if (bIsRamEncryptionEnabled) { cryptoInfo = cryptoInfoBackup; burn (&tmpCI, sizeof (CRYPTO_INFO)); @@ -926,7 +927,7 @@ static int ExpandVolume (HWND hwndDlg, wchar_t *lpszVolume, Password *pVolumePas LARGE_INTEGER hiddenOffset; #ifdef _WIN64 - if (IsRamEncryptionEnabled ()) + if (bIsRamEncryptionEnabled) { VirtualLock (&tmpCI, sizeof (CRYPTO_INFO)); memcpy (&tmpCI, cryptoInfo, sizeof (CRYPTO_INFO)); @@ -938,7 +939,7 @@ static int ExpandVolume (HWND hwndDlg, wchar_t *lpszVolume, Password *pVolumePas nStatus = WriteRandomDataToReservedHeaderAreas (hwndDlg, dev, cryptoInfo, newDataAreaSize, !backupHeader, backupHeader); #ifdef _WIN64 - if (IsRamEncryptionEnabled ()) + if (bIsRamEncryptionEnabled) { cryptoInfo = cryptoInfoBackup; burn (&tmpCI, sizeof (CRYPTO_INFO)); diff --git a/src/Format/InPlace.c b/src/Format/InPlace.c index d844be2c..4a16fd4f 100644 --- a/src/Format/InPlace.c +++ b/src/Format/InPlace.c @@ -774,6 +774,9 @@ int EncryptPartitionInPlaceResume (HANDLE dev, int pim = volParams->pim; DISK_GEOMETRY driveGeometry; HWND hwndDlg = volParams->hwndDlg; +#ifdef _WIN64 + BOOL bIsRamEncryptionEnabled = IsRamEncryptionEnabled(); +#endif bInPlaceEncNonSysResumed = TRUE; @@ -870,7 +873,7 @@ int EncryptPartitionInPlaceResume (HANDLE dev, goto closing_seq; #ifdef _WIN64 - if (IsRamEncryptionEnabled ()) + if (bIsRamEncryptionEnabled) { VcProtectKeys (masterCryptoInfo, VcGetEncryptionID (masterCryptoInfo)); VcProtectKeys (headerCryptoInfo, VcGetEncryptionID (headerCryptoInfo)); @@ -1100,7 +1103,7 @@ inplace_enc_read: #ifdef _WIN64 CRYPTO_INFO tmpCI; PCRYPTO_INFO cryptoInfoBackup = NULL; - if (IsRamEncryptionEnabled ()) + if (bIsRamEncryptionEnabled) { VirtualLock (&tmpCI, sizeof(tmpCI)); memcpy (&tmpCI, masterCryptoInfo, sizeof (CRYPTO_INFO)); @@ -1129,7 +1132,7 @@ inplace_enc_read: wipeAlgorithm == TC_WIPE_NONE ? FALSE : (wipePass < PRAND_HEADER_WIPE_PASSES - 1)); #ifdef _WIN64 - if (IsRamEncryptionEnabled ()) + if (bIsRamEncryptionEnabled) { masterCryptoInfo = cryptoInfoBackup; burn (&tmpCI, sizeof (CRYPTO_INFO)); @@ -1151,7 +1154,7 @@ inplace_enc_read: } #ifdef _WIN64 - if (IsRamEncryptionEnabled ()) + if (bIsRamEncryptionEnabled) { VirtualLock (&tmpCI, sizeof(tmpCI)); memcpy (&tmpCI, headerCryptoInfo, sizeof (CRYPTO_INFO)); @@ -1164,7 +1167,7 @@ inplace_enc_read: nStatus = WriteRandomDataToReservedHeaderAreas (hwndDlg, dev, headerCryptoInfo, masterCryptoInfo->VolumeSize.Value, TRUE, FALSE); #ifdef _WIN64 - if (IsRamEncryptionEnabled ()) + if (bIsRamEncryptionEnabled) { headerCryptoInfo = cryptoInfoBackup; burn (&tmpCI, sizeof (CRYPTO_INFO)); @@ -1331,6 +1334,9 @@ int DecryptPartitionInPlace (volatile FORMAT_VOL_PARAMETERS *volParams, volatile int pkcs5_prf = volParams->pkcs5; int pim = volParams->pim; DISK_GEOMETRY driveGeometry; +#ifdef _WIN64 + BOOL bIsRamEncryptionEnabled = IsRamEncryptionEnabled(); +#endif buf = (char *) TCalloc (TC_MAX_NONSYS_INPLACE_ENC_WORK_CHUNK_SIZE); @@ -1438,7 +1444,7 @@ int DecryptPartitionInPlace (volatile FORMAT_VOL_PARAMETERS *volParams, volatile goto closing_seq; #ifdef _WIN64 - if (IsRamEncryptionEnabled ()) + if (bIsRamEncryptionEnabled) { VcProtectKeys (masterCryptoInfo, VcGetEncryptionID (masterCryptoInfo)); VcProtectKeys (headerCryptoInfo, VcGetEncryptionID (headerCryptoInfo)); @@ -1840,6 +1846,9 @@ int FastVolumeHeaderUpdate (HANDLE dev, CRYPTO_INFO *headerCryptoInfo, CRYPTO_IN uint32 headerCrc32; byte *fieldPos; PCRYPTO_INFO pCryptoInfo = headerCryptoInfo; +#ifdef _WIN64 + BOOL bIsRamEncryptionEnabled = IsRamEncryptionEnabled(); +#endif header = (byte *) TCalloc (TC_VOLUME_HEADER_EFFECTIVE_SIZE); @@ -1861,7 +1870,7 @@ int FastVolumeHeaderUpdate (HANDLE dev, CRYPTO_INFO *headerCryptoInfo, CRYPTO_IN } #ifdef _WIN64 - if (IsRamEncryptionEnabled()) + if (bIsRamEncryptionEnabled) { pCryptoInfo = crypto_open(); if (!pCryptoInfo) @@ -1915,7 +1924,7 @@ closing_seq: dwError = GetLastError(); #ifdef _WIN64 - if (IsRamEncryptionEnabled() && pCryptoInfo) + if (bIsRamEncryptionEnabled && pCryptoInfo) { crypto_close(pCryptoInfo); } diff --git a/src/Mount/Mount.c b/src/Mount/Mount.c index c95129f6..ca322280 100644 --- a/src/Mount/Mount.c +++ b/src/Mount/Mount.c @@ -5157,7 +5157,14 @@ static BOOL Dismount (HWND hwndDlg, int nDosDriveNo) WaitCursor (); if (nDosDriveNo == -2) + { nDosDriveNo = (char) (HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) - L'A'); + if (nDosDriveNo < 0 || nDosDriveNo >= 26) + { + NormalCursor (); + return FALSE; + } + } if (bCloseDismountedWindows) { -- cgit v1.2.3