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
@@ -321,24 +321,28 @@ Cipher *CipherGet (int id)
321 return NULL; 321 return NULL;
322} 322}
323 323
324char *CipherGetName (int cipherId) 324const char *CipherGetName (int cipherId)
325{ 325{
326 return CipherGet (cipherId) -> Name; 326 Cipher* pCipher = CipherGet (cipherId);
327 return pCipher? pCipher -> Name : "";
327} 328}
328 329
329int CipherGetBlockSize (int cipherId) 330int CipherGetBlockSize (int cipherId)
330{ 331{
331 return CipherGet (cipherId) -> BlockSize; 332 Cipher* pCipher = CipherGet (cipherId);
333 return pCipher? pCipher -> BlockSize : 0;
332} 334}
333 335
334int CipherGetKeySize (int cipherId) 336int CipherGetKeySize (int cipherId)
335{ 337{
336 return CipherGet (cipherId) -> KeySize; 338 Cipher* pCipher = CipherGet (cipherId);
339 return pCipher? pCipher -> KeySize : 0;
337} 340}
338 341
339int CipherGetKeyScheduleSize (int cipherId) 342int CipherGetKeyScheduleSize (int cipherId)
340{ 343{
341 return CipherGet (cipherId) -> KeyScheduleSize; 344 Cipher* pCipher = CipherGet (cipherId);
345 return pCipher? pCipher -> KeyScheduleSize : 0;
342} 346}
343 347
344#ifndef TC_WINDOWS_BOOT 348#ifndef TC_WINDOWS_BOOT
@@ -715,15 +719,17 @@ int HashGetIdByName (char *name)
715} 719}
716 720
717 721
718char *HashGetName (int hashId) 722const char *HashGetName (int hashId)
719{ 723{
720 return HashGet (hashId) -> Name; 724 Hash* pHash = HashGet(hashId);
725 return pHash? pHash -> Name : "";
721} 726}
722 727
723 728
724BOOL HashIsDeprecated (int hashId) 729BOOL HashIsDeprecated (int hashId)
725{ 730{
726 return HashGet (hashId) -> Deprecated; 731 Hash* pHash = HashGet(hashId);
732 return pHash? pHash -> Deprecated : FALSE;
727} 733}
728 734
729 735
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
@@ -269,7 +269,7 @@ int CipherGetBlockSize (int cipher);
269int CipherGetKeySize (int cipher); 269int CipherGetKeySize (int cipher);
270int CipherGetKeyScheduleSize (int cipher); 270int CipherGetKeyScheduleSize (int cipher);
271BOOL CipherSupportsIntraDataUnitParallelization (int cipher); 271BOOL CipherSupportsIntraDataUnitParallelization (int cipher);
272char * CipherGetName (int cipher); 272const char * CipherGetName (int cipher);
273 273
274int CipherInit (int cipher, unsigned char *key, unsigned char *ks); 274int CipherInit (int cipher, unsigned char *key, unsigned char *ks);
275int EAInit (int ea, unsigned char *key, unsigned char *ks); 275int EAInit (int ea, unsigned char *key, unsigned char *ks);
@@ -302,7 +302,7 @@ int EAGetPreviousCipher (int ea, int previousCipherId);
302int EAIsFormatEnabled (int ea); 302int EAIsFormatEnabled (int ea);
303BOOL EAIsModeSupported (int ea, int testedMode); 303BOOL EAIsModeSupported (int ea, int testedMode);
304 304
305char *HashGetName (int hash_algo_id); 305const char *HashGetName (int hash_algo_id);
306BOOL HashIsDeprecated (int hashId); 306BOOL HashIsDeprecated (int hashId);
307 307
308int GetMaxPkcs5OutSize (void); 308int GetMaxPkcs5OutSize (void);
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
@@ -66,15 +66,20 @@ BOOL CheckPasswordCharEncoding (HWND hPassword, Password *ptrPw)
66 66
67 if (hPassword == NULL) 67 if (hPassword == NULL)
68 { 68 {
69 unsigned char *pw; 69 if (ptrPw)
70 len = ptrPw->Length;
71 pw = (unsigned char *) ptrPw->Text;
72
73 for (i = 0; i < len; i++)
74 { 70 {
75 if (pw[i] >= 0x7f || pw[i] < 0x20) // A non-ASCII or non-printable character? 71 unsigned char *pw;
76 return FALSE; 72 len = ptrPw->Length;
73 pw = (unsigned char *) ptrPw->Text;
74
75 for (i = 0; i < len; i++)
76 {
77 if (pw[i] >= 0x7f || pw[i] < 0x20) // A non-ASCII or non-printable character?
78 return FALSE;
79 }
77 } 80 }
81 else
82 return FALSE;
78 } 83 }
79 else 84 else
80 { 85 {
@@ -114,7 +119,7 @@ BOOL CheckPasswordLength (HWND hwndDlg, HWND hwndItem)
114 return TRUE; 119 return TRUE;
115} 120}
116 121
117int ChangePwd (char *lpszVolume, Password *oldPassword, Password *newPassword, int pkcs5, HWND hwndDlg) 122int ChangePwd (const char *lpszVolume, Password *oldPassword, Password *newPassword, int pkcs5, HWND hwndDlg)
118{ 123{
119 int nDosLinkCreated = 1, nStatus = ERR_OS_ERROR; 124 int nDosLinkCreated = 1, nStatus = ERR_OS_ERROR;
120 char szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH]; 125 char szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
@@ -138,9 +143,16 @@ int ChangePwd (char *lpszVolume, Password *oldPassword, Password *newPassword, i
138 143
139 if (oldPassword->Length == 0 || newPassword->Length == 0) return -1; 144 if (oldPassword->Length == 0 || newPassword->Length == 0) return -1;
140 145
146 if (!lpszVolume)
147 {
148 nStatus = ERR_OUTOFMEMORY;
149 handleError (hwndDlg, nStatus);
150 return nStatus;
151 }
152
141 WaitCursor (); 153 WaitCursor ();
142 154
143 CreateFullVolumePath (szDiskFile, lpszVolume, &bDevice); 155 CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), lpszVolume, &bDevice);
144 156
145 if (bDevice == FALSE) 157 if (bDevice == FALSE)
146 { 158 {
@@ -148,7 +160,7 @@ int ChangePwd (char *lpszVolume, Password *oldPassword, Password *newPassword, i
148 } 160 }
149 else 161 else
150 { 162 {
151 nDosLinkCreated = FakeDosNameForDevice (szDiskFile, szDosDevice, szCFDevice, FALSE); 163 nDosLinkCreated = FakeDosNameForDevice (szDiskFile, szDosDevice, sizeof(szDosDevice), szCFDevice, sizeof(szCFDevice),FALSE);
152 164
153 if (nDosLinkCreated != 0) 165 if (nDosLinkCreated != 0)
154 goto error; 166 goto error;
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
@@ -35,7 +35,7 @@ typedef struct
35void VerifyPasswordAndUpdate ( HWND hwndDlg , HWND hButton , HWND hPassword , HWND hVerify , unsigned char *szPassword , char *szVerify, BOOL keyFilesEnabled ); 35void VerifyPasswordAndUpdate ( HWND hwndDlg , HWND hButton , HWND hPassword , HWND hVerify , unsigned char *szPassword , char *szVerify, BOOL keyFilesEnabled );
36BOOL CheckPasswordLength (HWND hwndDlg, HWND hwndItem); 36BOOL CheckPasswordLength (HWND hwndDlg, HWND hwndItem);
37BOOL CheckPasswordCharEncoding (HWND hPassword, Password *ptrPw); 37BOOL CheckPasswordCharEncoding (HWND hPassword, Password *ptrPw);
38int ChangePwd (char *lpszVolume, Password *oldPassword, Password *newPassword, int pkcs5, HWND hwndDlg); 38int ChangePwd (const char *lpszVolume, Password *oldPassword, Password *newPassword, int pkcs5, HWND hwndDlg);
39 39
40#endif // defined(_WIN32) && !defined(TC_WINDOWS_DRIVER) 40#endif // defined(_WIN32) && !defined(TC_WINDOWS_DRIVER)
41 41