VeraCrypt
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2014-07-14 17:32:57 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2014-11-08 23:21:21 +0100
commitbbc738c490bcd691151c28f971e0e153777fb255 (patch)
tree81d6c3dbca12021fc8dd9563462c19836f5591a6
parent8bf58486af14c662ed63abea093886bfcf2ddbe5 (diff)
downloadVeraCrypt-bbc738c490bcd691151c28f971e0e153777fb255.tar.gz
VeraCrypt-bbc738c490bcd691151c28f971e0e153777fb255.zip
Static Code Analysis : Add various NULL pointers checks
-rw-r--r--src/Common/Crypto.c22
-rw-r--r--src/Common/Crypto.h4
-rw-r--r--src/Common/Password.c32
-rw-r--r--src/Common/Password.h2
4 files changed, 39 insertions, 21 deletions
diff --git a/src/Common/Crypto.c b/src/Common/Crypto.c
index 3b87572a..dd30e488 100644
--- a/src/Common/Crypto.c
+++ b/src/Common/Crypto.c
@@ -304,58 +304,62 @@ void DecipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount)
data += blockSize;
}
}
}
#endif // !TC_WINDOWS_BOOT
// Ciphers support
Cipher *CipherGet (int id)
{
int i;
for (i = 0; Ciphers[i].Id != 0; i++)
if (Ciphers[i].Id == id)
return &Ciphers[i];
return NULL;
}
-char *CipherGetName (int cipherId)
+const char *CipherGetName (int cipherId)
{
- return CipherGet (cipherId) -> Name;
+ Cipher* pCipher = CipherGet (cipherId);
+ return pCipher? pCipher -> Name : "";
}
int CipherGetBlockSize (int cipherId)
{
- return CipherGet (cipherId) -> BlockSize;
+ Cipher* pCipher = CipherGet (cipherId);
+ return pCipher? pCipher -> BlockSize : 0;
}
int CipherGetKeySize (int cipherId)
{
- return CipherGet (cipherId) -> KeySize;
+ Cipher* pCipher = CipherGet (cipherId);
+ return pCipher? pCipher -> KeySize : 0;
}
int CipherGetKeyScheduleSize (int cipherId)
{
- return CipherGet (cipherId) -> KeyScheduleSize;
+ Cipher* pCipher = CipherGet (cipherId);
+ return pCipher? pCipher -> KeyScheduleSize : 0;
}
#ifndef TC_WINDOWS_BOOT
BOOL CipherSupportsIntraDataUnitParallelization (int cipher)
{
return cipher == AES && IsAesHwCpuSupported();
}
#endif
// Encryption algorithms support
int EAGetFirst ()
{
return 1;
}
// Returns number of EAs
@@ -698,49 +702,51 @@ Hash *HashGet (int id)
int i;
for (i = 0; Hashes[i].Id != 0; i++)
if (Hashes[i].Id == id)
return &Hashes[i];
return 0;
}
int HashGetIdByName (char *name)
{
int i;
for (i = 0; Hashes[i].Id != 0; i++)
if (strcmp (Hashes[i].Name, name) == 0)
return Hashes[i].Id;
return 0;
}
-char *HashGetName (int hashId)
+const char *HashGetName (int hashId)
{
- return HashGet (hashId) -> Name;
+ Hash* pHash = HashGet(hashId);
+ return pHash? pHash -> Name : "";
}
BOOL HashIsDeprecated (int hashId)
{
- return HashGet (hashId) -> Deprecated;
+ Hash* pHash = HashGet(hashId);
+ return pHash? pHash -> Deprecated : FALSE;
}
#endif // TC_WINDOWS_BOOT_SINGLE_CIPHER_MODE
#ifdef TC_WINDOWS_BOOT
static byte CryptoInfoBufferInUse = 0;
CRYPTO_INFO CryptoInfoBuffer;
#endif
PCRYPTO_INFO crypto_open ()
{
#ifndef TC_WINDOWS_BOOT
/* Do the crt allocation */
PCRYPTO_INFO cryptoInfo = (PCRYPTO_INFO) TCalloc (sizeof (CRYPTO_INFO));
if (cryptoInfo == NULL)
diff --git a/src/Common/Crypto.h b/src/Common/Crypto.h
index dd35eeca..4f47ec04 100644
--- a/src/Common/Crypto.h
+++ b/src/Common/Crypto.h
@@ -252,74 +252,74 @@ typedef struct CRYPTO_INFO_t
#endif // !TC_WINDOWS_BOOT
UINT64_STRUCT VolumeSize;
UINT64_STRUCT EncryptedAreaStart;
UINT64_STRUCT EncryptedAreaLength;
uint32 HeaderFlags;
} CRYPTO_INFO, *PCRYPTO_INFO;
PCRYPTO_INFO crypto_open (void);
void crypto_loadkey (PKEY_INFO keyInfo, char *lpszUserKey, int nUserKeyLen);
void crypto_close (PCRYPTO_INFO cryptoInfo);
int CipherGetBlockSize (int cipher);
int CipherGetKeySize (int cipher);
int CipherGetKeyScheduleSize (int cipher);
BOOL CipherSupportsIntraDataUnitParallelization (int cipher);
-char * CipherGetName (int cipher);
+const char * CipherGetName (int cipher);
int CipherInit (int cipher, unsigned char *key, unsigned char *ks);
int EAInit (int ea, unsigned char *key, unsigned char *ks);
BOOL EAInitMode (PCRYPTO_INFO ci);
void EncipherBlock(int cipher, void *data, void *ks);
void DecipherBlock(int cipher, void *data, void *ks);
#ifndef TC_WINDOWS_BOOT
void EncipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount);
void DecipherBlocks (int cipher, void *dataPtr, void *ks, size_t blockCount);
#endif
int EAGetFirst ();
int EAGetCount (void);
int EAGetNext (int previousEA);
char * EAGetName (char *buf, int ea);
int EAGetByName (char *name);
int EAGetKeySize (int ea);
int EAGetFirstMode (int ea);
int EAGetNextMode (int ea, int previousModeId);
char * EAGetModeName (int ea, int mode, BOOL capitalLetters);
int EAGetKeyScheduleSize (int ea);
int EAGetLargestKey ();
int EAGetLargestKeyForMode (int mode);
int EAGetCipherCount (int ea);
int EAGetFirstCipher (int ea);
int EAGetLastCipher (int ea);
int EAGetNextCipher (int ea, int previousCipherId);
int EAGetPreviousCipher (int ea, int previousCipherId);
int EAIsFormatEnabled (int ea);
BOOL EAIsModeSupported (int ea, int testedMode);
-char *HashGetName (int hash_algo_id);
+const char *HashGetName (int hash_algo_id);
BOOL HashIsDeprecated (int hashId);
int GetMaxPkcs5OutSize (void);
void EncryptDataUnits (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, uint32 nbrUnits, PCRYPTO_INFO ci);
void EncryptDataUnitsCurrentThread (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, TC_LARGEST_COMPILER_UINT nbrUnits, PCRYPTO_INFO ci);
void DecryptDataUnits (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, uint32 nbrUnits, PCRYPTO_INFO ci);
void DecryptDataUnitsCurrentThread (unsigned __int8 *buf, const UINT64_STRUCT *structUnitNo, TC_LARGEST_COMPILER_UINT nbrUnits, PCRYPTO_INFO ci);
void EncryptBuffer (unsigned __int8 *buf, TC_LARGEST_COMPILER_UINT len, PCRYPTO_INFO cryptoInfo);
void DecryptBuffer (unsigned __int8 *buf, TC_LARGEST_COMPILER_UINT len, PCRYPTO_INFO cryptoInfo);
#ifndef TC_NO_COMPILER_INT64
void EncryptBufferLRW128 (byte *buffer, uint64 length, uint64 blockIndex, PCRYPTO_INFO cryptoInfo);
void DecryptBufferLRW128 (byte *buffer, uint64 length, uint64 blockIndex, PCRYPTO_INFO cryptoInfo);
void EncryptBufferLRW64 (byte *buffer, uint64 length, uint64 blockIndex, PCRYPTO_INFO cryptoInfo);
void DecryptBufferLRW64 (byte *buffer, uint64 length, uint64 blockIndex, PCRYPTO_INFO cryptoInfo);
uint64 DataUnit2LRWIndex (uint64 dataUnit, int blockSize, PCRYPTO_INFO ci);
#endif // #ifndef TC_NO_COMPILER_INT64
BOOL IsAesHwCpuSupported ();
void EnableHwEncryption (BOOL enable);
diff --git a/src/Common/Password.c b/src/Common/Password.c
index 506a18c5..ca86f9c4 100644
--- a/src/Common/Password.c
+++ b/src/Common/Password.c
@@ -49,123 +49,135 @@ void VerifyPasswordAndUpdate (HWND hwndDlg, HWND hButton, HWND hPassword,
if (szPassword != NULL)
memcpy (szPassword, szTmp1, sizeof (szTmp1));
if (szVerify != NULL)
memcpy (szVerify, szTmp2, sizeof (szTmp2));
burn (szTmp1, sizeof (szTmp1));
burn (szTmp2, sizeof (szTmp2));
EnableWindow (hButton, bEnable);
}
BOOL CheckPasswordCharEncoding (HWND hPassword, Password *ptrPw)
{
int i, len;
if (hPassword == NULL)
{
- unsigned char *pw;
- len = ptrPw->Length;
- pw = (unsigned char *) ptrPw->Text;
-
- for (i = 0; i < len; i++)
+ if (ptrPw)
{
- if (pw[i] >= 0x7f || pw[i] < 0x20) // A non-ASCII or non-printable character?
- return FALSE;
+ unsigned char *pw;
+ len = ptrPw->Length;
+ pw = (unsigned char *) ptrPw->Text;
+
+ for (i = 0; i < len; i++)
+ {
+ if (pw[i] >= 0x7f || pw[i] < 0x20) // A non-ASCII or non-printable character?
+ return FALSE;
+ }
}
+ else
+ return FALSE;
}
else
{
wchar_t s[MAX_PASSWORD + 1];
len = GetWindowTextLength (hPassword);
if (len > MAX_PASSWORD)
return FALSE;
GetWindowTextW (hPassword, s, sizeof (s) / sizeof (wchar_t));
for (i = 0; i < len; i++)
{
if (s[i] >= 0x7f || s[i] < 0x20) // A non-ASCII or non-printable character?
break;
}
burn (s, sizeof(s));
if (i < len)
return FALSE;
}
return TRUE;
}
BOOL CheckPasswordLength (HWND hwndDlg, HWND hwndItem)
{
if (GetWindowTextLength (hwndItem) < PASSWORD_LEN_WARNING)
{
#ifndef _DEBUG
if (MessageBoxW (hwndDlg, GetString ("PASSWORD_LENGTH_WARNING"), lpszTitle, MB_YESNO|MB_ICONWARNING|MB_DEFBUTTON2) != IDYES)
return FALSE;
#endif
}
return TRUE;
}
-int ChangePwd (char *lpszVolume, Password *oldPassword, Password *newPassword, int pkcs5, HWND hwndDlg)
+int ChangePwd (const char *lpszVolume, Password *oldPassword, Password *newPassword, int pkcs5, HWND hwndDlg)
{
int nDosLinkCreated = 1, nStatus = ERR_OS_ERROR;
char szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
char szDosDevice[TC_MAX_PATH];
char buffer[TC_VOLUME_HEADER_EFFECTIVE_SIZE];
PCRYPTO_INFO cryptoInfo = NULL, ci = NULL;
void *dev = INVALID_HANDLE_VALUE;
DWORD dwError;
DWORD bytesRead;
BOOL bDevice;
unsigned __int64 hostSize = 0;
int volumeType;
int wipePass;
FILETIME ftCreationTime;
FILETIME ftLastWriteTime;
FILETIME ftLastAccessTime;
BOOL bTimeStampValid = FALSE;
LARGE_INTEGER headerOffset;
BOOL backupHeader;
DISK_GEOMETRY driveInfo;
if (oldPassword->Length == 0 || newPassword->Length == 0) return -1;
+ if (!lpszVolume)
+ {
+ nStatus = ERR_OUTOFMEMORY;
+ handleError (hwndDlg, nStatus);
+ return nStatus;
+ }
+
WaitCursor ();
- CreateFullVolumePath (szDiskFile, lpszVolume, &bDevice);
+ CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), lpszVolume, &bDevice);
if (bDevice == FALSE)
{
strcpy (szCFDevice, szDiskFile);
}
else
{
- nDosLinkCreated = FakeDosNameForDevice (szDiskFile, szDosDevice, szCFDevice, FALSE);
+ nDosLinkCreated = FakeDosNameForDevice (szDiskFile, szDosDevice, sizeof(szDosDevice), szCFDevice, sizeof(szCFDevice),FALSE);
if (nDosLinkCreated != 0)
goto error;
}
dev = CreateFile (szCFDevice, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if (dev == INVALID_HANDLE_VALUE)
goto error;
if (bDevice)
{
/* This is necessary to determine the hidden volume header offset */
if (dev == INVALID_HANDLE_VALUE)
{
goto error;
}
else
{
diff --git a/src/Common/Password.h b/src/Common/Password.h
index 25028b11..d4f1f928 100644
--- a/src/Common/Password.h
+++ b/src/Common/Password.h
@@ -18,29 +18,29 @@
#define PASSWORD_LEN_WARNING 20 // Display a warning when a password is shorter than this
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
// Modifying this structure can introduce incompatibility with previous versions
unsigned __int32 Length;
unsigned char Text[MAX_PASSWORD + 1];
char Pad[3]; // keep 64-bit alignment
} Password;
#if defined(_WIN32) && !defined(TC_WINDOWS_DRIVER)
void VerifyPasswordAndUpdate ( HWND hwndDlg , HWND hButton , HWND hPassword , HWND hVerify , unsigned char *szPassword , char *szVerify, BOOL keyFilesEnabled );
BOOL CheckPasswordLength (HWND hwndDlg, HWND hwndItem);
BOOL CheckPasswordCharEncoding (HWND hPassword, Password *ptrPw);
-int ChangePwd (char *lpszVolume, Password *oldPassword, Password *newPassword, int pkcs5, HWND hwndDlg);
+int ChangePwd (const char *lpszVolume, Password *oldPassword, Password *newPassword, int pkcs5, HWND hwndDlg);
#endif // defined(_WIN32) && !defined(TC_WINDOWS_DRIVER)
#ifdef __cplusplus
}
#endif
#endif // PASSWORD_H