VeraCrypt
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2014-07-14 17:24:13 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2014-11-08 23:21:18 +0100
commit8bf58486af14c662ed63abea093886bfcf2ddbe5 (patch)
tree66c7762a8a5e2f594b935e609f7219afb6f415f2
parentba733dd032a44eb38653abe922fc6905413bcac4 (diff)
downloadVeraCrypt-8bf58486af14c662ed63abea093886bfcf2ddbe5.tar.gz
VeraCrypt-8bf58486af14c662ed63abea093886bfcf2ddbe5.zip
Static Code Analysis : Add NULL pointers checks on the result of ATL string conversion. Avoid some conversions by using UNICODE functions directly.
-rw-r--r--src/Common/BaseCom.cpp16
-rw-r--r--src/Mount/MainCom.cpp18
2 files changed, 24 insertions, 10 deletions
diff --git a/src/Common/BaseCom.cpp b/src/Common/BaseCom.cpp
index 5771daaa..69c614af 100644
--- a/src/Common/BaseCom.cpp
+++ b/src/Common/BaseCom.cpp
@@ -83,9 +83,8 @@ DWORD BaseCom::CallDriver (DWORD ioctl, BSTR input, BSTR *output)
83 83
84DWORD BaseCom::CopyFile (BSTR sourceFile, BSTR destinationFile) 84DWORD BaseCom::CopyFile (BSTR sourceFile, BSTR destinationFile)
85{ 85{
86 USES_CONVERSION;
87 86
88 if (!::CopyFile (CW2A (sourceFile), CW2A (destinationFile), FALSE)) 87 if (!::CopyFileW (sourceFile, destinationFile, FALSE))
89 return GetLastError(); 88 return GetLastError();
90 89
91 return ERROR_SUCCESS; 90 return ERROR_SUCCESS;
@@ -94,9 +93,8 @@ DWORD BaseCom::CopyFile (BSTR sourceFile, BSTR destinationFile)
94 93
95DWORD BaseCom::DeleteFile (BSTR file) 94DWORD BaseCom::DeleteFile (BSTR file)
96{ 95{
97 USES_CONVERSION;
98 96
99 if (!::DeleteFile (CW2A (file))) 97 if (!::DeleteFileW (file))
100 return GetLastError(); 98 return GetLastError();
101 99
102 return ERROR_SUCCESS; 100 return ERROR_SUCCESS;
@@ -112,10 +110,15 @@ BOOL BaseCom::IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly)
112DWORD BaseCom::ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *bufferBstr, unsigned __int64 offset, unsigned __int32 size, DWORD *sizeDone) 110DWORD BaseCom::ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *bufferBstr, unsigned __int64 offset, unsigned __int32 size, DWORD *sizeDone)
113{ 111{
114 USES_CONVERSION; 112 USES_CONVERSION;
113 CW2A szFilePathA(filePath);
114 if (!szFilePathA.m_psz)
115 {
116 return ERROR_NOT_ENOUGH_MEMORY;
117 }
115 118
116 try 119 try
117 { 120 {
118 auto_ptr <File> file (device ? new Device (string (CW2A (filePath)), !write) : new File (string (CW2A (filePath)), !write)); 121 auto_ptr <File> file (device ? new Device (string (szFilePathA.m_psz), !write) : new File (string (szFilePathA.m_psz), !write));
119 file->SeekAt (offset); 122 file->SeekAt (offset);
120 123
121 if (write) 124 if (write)
@@ -223,8 +226,7 @@ DWORD BaseCom::SetDriverServiceStartType (DWORD startType)
223 226
224DWORD BaseCom::WriteLocalMachineRegistryDwordValue (BSTR keyPath, BSTR valueName, DWORD value) 227DWORD BaseCom::WriteLocalMachineRegistryDwordValue (BSTR keyPath, BSTR valueName, DWORD value)
225{ 228{
226 USES_CONVERSION; 229 if (!::WriteLocalMachineRegistryDwordW (keyPath, valueName, value))
227 if (!::WriteLocalMachineRegistryDword (CW2A (keyPath), CW2A (valueName), value))
228 return GetLastError(); 230 return GetLastError();
229 231
230 return ERROR_SUCCESS; 232 return ERROR_SUCCESS;
diff --git a/src/Mount/MainCom.cpp b/src/Mount/MainCom.cpp
index 0ac0253e..537a187f 100644
--- a/src/Mount/MainCom.cpp
+++ b/src/Mount/MainCom.cpp
@@ -76,15 +76,23 @@ public:
76 virtual int STDMETHODCALLTYPE BackupVolumeHeader (LONG_PTR hwndDlg, BOOL bRequireConfirmation, BSTR lpszVolume) 76 virtual int STDMETHODCALLTYPE BackupVolumeHeader (LONG_PTR hwndDlg, BOOL bRequireConfirmation, BSTR lpszVolume)
77 { 77 {
78 USES_CONVERSION; 78 USES_CONVERSION;
79 CW2A szVolumeA(lpszVolume);
79 MainDlg = (HWND) hwndDlg; 80 MainDlg = (HWND) hwndDlg;
80 return ::BackupVolumeHeader ((HWND) hwndDlg, bRequireConfirmation, CW2A (lpszVolume)); 81 if (szVolumeA.m_psz)
82 return ::BackupVolumeHeader ((HWND) hwndDlg, bRequireConfirmation, szVolumeA.m_psz);
83 else
84 return ERR_OUTOFMEMORY;
81 } 85 }
82 86
83 virtual int STDMETHODCALLTYPE RestoreVolumeHeader (LONG_PTR hwndDlg, BSTR lpszVolume) 87 virtual int STDMETHODCALLTYPE RestoreVolumeHeader (LONG_PTR hwndDlg, BSTR lpszVolume)
84 { 88 {
85 USES_CONVERSION; 89 USES_CONVERSION;
90 CW2A szVolumeA(lpszVolume);
86 MainDlg = (HWND) hwndDlg; 91 MainDlg = (HWND) hwndDlg;
87 return ::RestoreVolumeHeader ((HWND) hwndDlg, CW2A (lpszVolume)); 92 if (szVolumeA.m_psz)
93 return ::RestoreVolumeHeader ((HWND) hwndDlg, szVolumeA.m_psz);
94 else
95 return ERR_OUTOFMEMORY;
88 } 96 }
89 97
90 virtual DWORD STDMETHODCALLTYPE CallDriver (DWORD ioctl, BSTR input, BSTR *output) 98 virtual DWORD STDMETHODCALLTYPE CallDriver (DWORD ioctl, BSTR input, BSTR *output)
@@ -95,8 +103,12 @@ public:
95 virtual int STDMETHODCALLTYPE ChangePassword (BSTR volumePath, Password *oldPassword, Password *newPassword, int pkcs5, LONG_PTR hWnd) 103 virtual int STDMETHODCALLTYPE ChangePassword (BSTR volumePath, Password *oldPassword, Password *newPassword, int pkcs5, LONG_PTR hWnd)
96 { 104 {
97 USES_CONVERSION; 105 USES_CONVERSION;
106 CW2A volumePathA(volumePath);
98 MainDlg = (HWND) hWnd; 107 MainDlg = (HWND) hWnd;
99 return ::ChangePwd (CW2A (volumePath), oldPassword, newPassword, pkcs5, (HWND) hWnd); 108 if (volumePathA.m_psz)
109 return ::ChangePwd (volumePathA.m_psz, oldPassword, newPassword, pkcs5, (HWND) hWnd);
110 else
111 return ERR_OUTOFMEMORY;
100 } 112 }
101 113
102 virtual DWORD STDMETHODCALLTYPE CopyFile (BSTR sourceFile, BSTR destinationFile) 114 virtual DWORD STDMETHODCALLTYPE CopyFile (BSTR sourceFile, BSTR destinationFile)