VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src
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 /src
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.
Diffstat (limited to 'src')
-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)
DWORD BaseCom::CopyFile (BSTR sourceFile, BSTR destinationFile)
{
- USES_CONVERSION;
- if (!::CopyFile (CW2A (sourceFile), CW2A (destinationFile), FALSE))
+ if (!::CopyFileW (sourceFile, destinationFile, FALSE))
return GetLastError();
return ERROR_SUCCESS;
@@ -94,9 +93,8 @@ DWORD BaseCom::CopyFile (BSTR sourceFile, BSTR destinationFile)
DWORD BaseCom::DeleteFile (BSTR file)
{
- USES_CONVERSION;
- if (!::DeleteFile (CW2A (file)))
+ if (!::DeleteFileW (file))
return GetLastError();
return ERROR_SUCCESS;
@@ -112,10 +110,15 @@ BOOL BaseCom::IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly)
DWORD BaseCom::ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *bufferBstr, unsigned __int64 offset, unsigned __int32 size, DWORD *sizeDone)
{
USES_CONVERSION;
+ CW2A szFilePathA(filePath);
+ if (!szFilePathA.m_psz)
+ {
+ return ERROR_NOT_ENOUGH_MEMORY;
+ }
try
{
- auto_ptr <File> file (device ? new Device (string (CW2A (filePath)), !write) : new File (string (CW2A (filePath)), !write));
+ auto_ptr <File> file (device ? new Device (string (szFilePathA.m_psz), !write) : new File (string (szFilePathA.m_psz), !write));
file->SeekAt (offset);
if (write)
@@ -223,8 +226,7 @@ DWORD BaseCom::SetDriverServiceStartType (DWORD startType)
DWORD BaseCom::WriteLocalMachineRegistryDwordValue (BSTR keyPath, BSTR valueName, DWORD value)
{
- USES_CONVERSION;
- if (!::WriteLocalMachineRegistryDword (CW2A (keyPath), CW2A (valueName), value))
+ if (!::WriteLocalMachineRegistryDwordW (keyPath, valueName, value))
return GetLastError();
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:
virtual int STDMETHODCALLTYPE BackupVolumeHeader (LONG_PTR hwndDlg, BOOL bRequireConfirmation, BSTR lpszVolume)
{
USES_CONVERSION;
+ CW2A szVolumeA(lpszVolume);
MainDlg = (HWND) hwndDlg;
- return ::BackupVolumeHeader ((HWND) hwndDlg, bRequireConfirmation, CW2A (lpszVolume));
+ if (szVolumeA.m_psz)
+ return ::BackupVolumeHeader ((HWND) hwndDlg, bRequireConfirmation, szVolumeA.m_psz);
+ else
+ return ERR_OUTOFMEMORY;
}
virtual int STDMETHODCALLTYPE RestoreVolumeHeader (LONG_PTR hwndDlg, BSTR lpszVolume)
{
USES_CONVERSION;
+ CW2A szVolumeA(lpszVolume);
MainDlg = (HWND) hwndDlg;
- return ::RestoreVolumeHeader ((HWND) hwndDlg, CW2A (lpszVolume));
+ if (szVolumeA.m_psz)
+ return ::RestoreVolumeHeader ((HWND) hwndDlg, szVolumeA.m_psz);
+ else
+ return ERR_OUTOFMEMORY;
}
virtual DWORD STDMETHODCALLTYPE CallDriver (DWORD ioctl, BSTR input, BSTR *output)
@@ -95,8 +103,12 @@ public:
virtual int STDMETHODCALLTYPE ChangePassword (BSTR volumePath, Password *oldPassword, Password *newPassword, int pkcs5, LONG_PTR hWnd)
{
USES_CONVERSION;
+ CW2A volumePathA(volumePath);
MainDlg = (HWND) hWnd;
- return ::ChangePwd (CW2A (volumePath), oldPassword, newPassword, pkcs5, (HWND) hWnd);
+ if (volumePathA.m_psz)
+ return ::ChangePwd (volumePathA.m_psz, oldPassword, newPassword, pkcs5, (HWND) hWnd);
+ else
+ return ERR_OUTOFMEMORY;
}
virtual DWORD STDMETHODCALLTYPE CopyFile (BSTR sourceFile, BSTR destinationFile)