Windows: Fix various issues detected by static analysis.

This commit is contained in:
Mounir IDRASSI 2016-08-16 04:04:31 +02:00
parent 1bf219b0dc
commit ce76957a10
No known key found for this signature in database
GPG Key ID: DD0C382D5FCFB8FC
8 changed files with 37 additions and 30 deletions

View File

@ -198,6 +198,9 @@ namespace VeraCrypt
if (bstr) if (bstr)
{ {
CComBSTR inputBstr; CComBSTR inputBstr;
CComBSTR fileBstr;
fileBstr.Attach (bstr);
if (input && inputBstr.AppendBytes ((const char *) input, inputSize) != S_OK) if (input && inputBstr.AppendBytes ((const char *) input, inputSize) != S_OK)
{ {
SetLastError (ERROR_INVALID_PARAMETER); SetLastError (ERROR_INVALID_PARAMETER);
@ -211,8 +214,6 @@ namespace VeraCrypt
return FALSE; return FALSE;
} }
CComBSTR fileBstr;
fileBstr.Attach (bstr);
result = ElevatedComInstance->DeviceIoControl (readOnly, device, fileBstr, dwIoControlCode, inputBstr, &outputBstr); result = ElevatedComInstance->DeviceIoControl (readOnly, device, fileBstr, dwIoControlCode, inputBstr, &outputBstr);
if (output) if (output)
@ -2071,6 +2072,8 @@ namespace VeraCrypt
EfiBoot::EfiBoot() { EfiBoot::EfiBoot() {
ZeroMemory(EfiBootPartPath, sizeof(EfiBootPartPath)); ZeroMemory(EfiBootPartPath, sizeof(EfiBootPartPath));
ZeroMemory (systemPartitionPath, sizeof (systemPartitionPath)); ZeroMemory (systemPartitionPath, sizeof (systemPartitionPath));
ZeroMemory (&sdn, sizeof (sdn));
ZeroMemory (&partInfo, sizeof (partInfo));
m_bMounted = false; m_bMounted = false;
} }
@ -2288,7 +2291,7 @@ namespace VeraCrypt
wchar_t varName[256]; wchar_t varName[256];
StringCchPrintfW(varName, ARRAYSIZE (varName), L"%s%04X", type == NULL ? L"Boot" : type, statrtOrderNum); StringCchPrintfW(varName, ARRAYSIZE (varName), L"%s%04X", type == NULL ? L"Boot" : type, statrtOrderNum);
SetFirmwareEnvironmentVariable(varName, EfiVarGuid, startVar, varSize); SetFirmwareEnvironmentVariable(varName, EfiVarGuid, startVar, varSize);
delete startVar; delete [] startVar;
// Update order // Update order
wstring order = L"Order"; wstring order = L"Order";

View File

@ -686,7 +686,7 @@ typedef struct zlist {
char iname[MAX_PATH]; // Internal file name after cleanup char iname[MAX_PATH]; // Internal file name after cleanup
char zname[MAX_PATH]; // External version of internal name char zname[MAX_PATH]; // External version of internal name
int mark; // Marker for files to operate on int mark; // Marker for files to operate on
int trash; // Marker for files to delete // int trash; // Marker for files to delete
int dosflag; // Set to force MSDOS file attributes int dosflag; // Set to force MSDOS file attributes
struct zlist far *nxt; // Pointer to next header in list struct zlist far *nxt; // Pointer to next header in list
} TZipFileInfo; } TZipFileInfo;

View File

@ -75,19 +75,19 @@ static void xor_s_box(byte s_box[8][16], byte *seed)
int i; int i;
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
{ {
s_box[1][i] ^= (seed[ (i * 4) + 0 ] ) & 0xF; s_box[0][i] ^= (seed[ (i * 4) + 0 ] ) & 0xF;
s_box[2][i] ^= (seed[ (i * 4) + 0 ]>>4) & 0xF; s_box[1][i] ^= (seed[ (i * 4) + 0 ]>>4) & 0xF;
s_box[3][i] ^= (seed[ (i * 4) + 1 ] ) & 0xF; s_box[2][i] ^= (seed[ (i * 4) + 1 ] ) & 0xF;
s_box[4][i] ^= (seed[ (i * 4) + 1 ]>>4) & 0xF; s_box[3][i] ^= (seed[ (i * 4) + 1 ]>>4) & 0xF;
s_box[5][i] ^= (seed[ (i * 4) + 2 ] ) & 0xF; s_box[4][i] ^= (seed[ (i * 4) + 2 ] ) & 0xF;
s_box[6][i] ^= (seed[ (i * 4) + 2 ]>>4) & 0xF; s_box[5][i] ^= (seed[ (i * 4) + 2 ]>>4) & 0xF;
s_box[7][i] ^= (seed[ (i * 4) + 3 ] ) & 0xF; s_box[6][i] ^= (seed[ (i * 4) + 3 ] ) & 0xF;
s_box[8][i] ^= (seed[ (i * 4) + 3 ]>>4) & 0xF; s_box[7][i] ^= (seed[ (i * 4) + 3 ]>>4) & 0xF;
} }
} }
#endif #endif
void gost_set_key(byte *key, gost_kds *ks) void gost_set_key(const byte *key, gost_kds *ks)
{ {
#ifdef GOST_DYNAMIC_SBOXES #ifdef GOST_DYNAMIC_SBOXES
STREEBOG_CTX sctx; STREEBOG_CTX sctx;
@ -228,11 +228,11 @@ void gost_decrypt_block(uint64 in_, uint64* out_, gost_kds* kds) {
} }
#if defined(_M_AMD64) #if defined(_M_AMD64)
void gost_encrypt_128_CBC_asm(byte *in, byte *out, gost_kds *ks, uint64 count); void gost_encrypt_128_CBC_asm(const byte *in, byte *out, gost_kds *ks, uint64 count);
void gost_decrypt_128_CBC_asm(byte *in, byte *out, gost_kds *ks, uint64 count); void gost_decrypt_128_CBC_asm(const byte *in, byte *out, gost_kds *ks, uint64 count);
#endif #endif
void gost_encrypt(byte *in, byte *out, gost_kds *ks, int count) { void gost_encrypt(const byte *in, byte *out, gost_kds *ks, int count) {
#if defined(_M_AMD64) #if defined(_M_AMD64)
gost_encrypt_128_CBC_asm(in, out, ks, (uint64)count); gost_encrypt_128_CBC_asm(in, out, ks, (uint64)count);
#else #else
@ -249,7 +249,7 @@ void gost_encrypt(byte *in, byte *out, gost_kds *ks, int count) {
#endif #endif
} }
void gost_decrypt(byte *in, byte *out, gost_kds *ks, int count) { void gost_decrypt(const byte *in, byte *out, gost_kds *ks, int count) {
#if defined(_M_AMD64) #if defined(_M_AMD64)
gost_decrypt_128_CBC_asm(in, out, ks, (uint64)count); gost_decrypt_128_CBC_asm(in, out, ks, (uint64)count);
#else #else

View File

@ -49,9 +49,9 @@ typedef struct gost_kds
#define GOST_KS (sizeof(gost_kds)) #define GOST_KS (sizeof(gost_kds))
void gost_encrypt(byte *in, byte *out, gost_kds *ks, int count); void gost_encrypt(const byte *in, byte *out, gost_kds *ks, int count);
void gost_decrypt(byte *in, byte *out, gost_kds *ks, int count); void gost_decrypt(const byte *in, byte *out, gost_kds *ks, int count);
void gost_set_key(byte *key, gost_kds *ks); void gost_set_key(const byte *key, gost_kds *ks);
#else #else
#define GOST_KS (0) #define GOST_KS (0)

View File

@ -2328,9 +2328,9 @@ stage3(STREEBOG_CTX *CTX)
memset(buf, 0x00, sizeof buf); memset(buf, 0x00, sizeof buf);
#ifndef __GOST3411_BIG_ENDIAN__ #ifndef __GOST3411_BIG_ENDIAN__
buf[0] = CTX->bufsize << 3; buf[0] = ((unsigned long long) CTX->bufsize) << 3;
#else #else
buf[0] = BSWAP64(CTX->bufsize << 3); buf[0] = BSWAP64(((unsigned long long) CTX->bufsize) << 3);
#endif #endif
pad(CTX); pad(CTX);

View File

@ -279,7 +279,7 @@ static int Detect_MS_HyperV_AES ()
void DetectX86Features() void DetectX86Features()
{ {
uint32 cpuid[4], cpuid1[4]; uint32 cpuid[4] = {0}, cpuid1[4] = {0};
if (!CpuId(0, cpuid)) if (!CpuId(0, cpuid))
return; return;
if (!CpuId(1, cpuid1)) if (!CpuId(1, cpuid1))

View File

@ -9206,17 +9206,19 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
{ {
wchar_t szTmp [TC_MAX_PATH + 8000] = {0}; wchar_t szTmp [TC_MAX_PATH + 8000] = {0};
GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs, szTmp, ARRAYSIZE (szTmp)); if ((HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs, szTmp, ARRAYSIZE (szTmp)))
&& (wcslen (szTmp) >= 1)
if (wcslen (szTmp) < 1) )
{
memset (szFileName, 0, sizeof (szFileName));
StringCbCopyW (szFileName, sizeof (szFileName), szTmp);
DirectNonSysInplaceDecStartMode = TRUE;
}
else
{ {
// No valid volume path specified as command-line parameter // No valid volume path specified as command-line parameter
AbortProcess ("ERR_PARAMETER_INCORRECT"); AbortProcess ("ERR_PARAMETER_INCORRECT");
} }
memset (szFileName, 0, sizeof (szFileName));
StringCbCopyW (szFileName, sizeof (szFileName), szTmp);
DirectNonSysInplaceDecStartMode = TRUE;
} }
break; break;

View File

@ -10980,6 +10980,8 @@ static BOOL CALLBACK BootLoaderPreferencesDlgProc (HWND hwndDlg, UINT msg, WPARA
CheckDlgButton (hwndDlg, IDC_DISABLE_BOOT_LOADER_PIM_PROMPT, BST_UNCHECKED); CheckDlgButton (hwndDlg, IDC_DISABLE_BOOT_LOADER_PIM_PROMPT, BST_UNCHECKED);
} }
break;
case IDC_DISABLE_BOOT_LOADER_OUTPUT: case IDC_DISABLE_BOOT_LOADER_OUTPUT:
if ((IsDlgButtonChecked (hwndDlg, IDC_DISABLE_BOOT_LOADER_OUTPUT)) if ((IsDlgButtonChecked (hwndDlg, IDC_DISABLE_BOOT_LOADER_OUTPUT))
&& AskWarnYesNo ("CUSTOM_BOOT_LOADER_MESSAGE_PROMPT", hwndDlg) == IDNO) && AskWarnYesNo ("CUSTOM_BOOT_LOADER_MESSAGE_PROMPT", hwndDlg) == IDNO)