1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 11:08:02 -06:00

Windows: in function CreateVolumeHeaderInMemory, properly unlock and erase sensitive stack memory.

This commit is contained in:
Mounir IDRASSI
2016-10-01 22:54:48 +02:00
parent 8e2c5ca45e
commit 34f3c055ed

View File

@@ -870,7 +870,8 @@ int CreateVolumeHeaderInMemory (HWND hwndDlg, BOOL bBoot, char *header, int ea,
#endif #endif
{ {
crypto_close (cryptoInfo); crypto_close (cryptoInfo);
return ERR_CIPHER_INIT_WEAK_KEY; retVal = ERR_CIPHER_INIT_WEAK_KEY;
goto err;
} }
} }
else else
@@ -912,7 +913,8 @@ int CreateVolumeHeaderInMemory (HWND hwndDlg, BOOL bBoot, char *header, int ea,
#endif #endif
{ {
crypto_close (cryptoInfo); crypto_close (cryptoInfo);
return ERR_CIPHER_INIT_WEAK_KEY; retVal = ERR_CIPHER_INIT_WEAK_KEY;
goto err;
} }
if (password) if (password)
@@ -961,7 +963,8 @@ int CreateVolumeHeaderInMemory (HWND hwndDlg, BOOL bBoot, char *header, int ea,
#endif #endif
{ {
crypto_close (cryptoInfo); crypto_close (cryptoInfo);
return ERR_CIPHER_INIT_WEAK_KEY; retVal = ERR_CIPHER_INIT_WEAK_KEY;
goto err;
} }
} }
@@ -1045,14 +1048,15 @@ int CreateVolumeHeaderInMemory (HWND hwndDlg, BOOL bBoot, char *header, int ea,
if (retVal != ERR_SUCCESS) if (retVal != ERR_SUCCESS)
{ {
crypto_close (cryptoInfo); crypto_close (cryptoInfo);
return retVal; goto err;
} }
// Mode of operation // Mode of operation
if (!EAInitMode (cryptoInfo)) if (!EAInitMode (cryptoInfo))
{ {
crypto_close (cryptoInfo); crypto_close (cryptoInfo);
return ERR_OUTOFMEMORY; retVal = ERR_OUTOFMEMORY;
goto err;
} }
@@ -1069,7 +1073,7 @@ int CreateVolumeHeaderInMemory (HWND hwndDlg, BOOL bBoot, char *header, int ea,
if (retVal != ERR_SUCCESS) if (retVal != ERR_SUCCESS)
{ {
crypto_close (cryptoInfo); crypto_close (cryptoInfo);
return retVal; goto err;
} }
memcpy (cryptoInfo->master_keydata, keyInfo.master_keydata, MASTER_KEYDATA_SIZE); memcpy (cryptoInfo->master_keydata, keyInfo.master_keydata, MASTER_KEYDATA_SIZE);
@@ -1086,7 +1090,8 @@ int CreateVolumeHeaderInMemory (HWND hwndDlg, BOOL bBoot, char *header, int ea,
if (!EAInitMode (cryptoInfo)) if (!EAInitMode (cryptoInfo))
{ {
crypto_close (cryptoInfo); crypto_close (cryptoInfo);
return ERR_OUTOFMEMORY; retVal = ERR_OUTOFMEMORY;
goto err;
} }
@@ -1132,10 +1137,16 @@ int CreateVolumeHeaderInMemory (HWND hwndDlg, BOOL bBoot, char *header, int ea,
} }
#endif // #ifdef VOLFORMAT #endif // #ifdef VOLFORMAT
*retInfo = cryptoInfo;
err:
burn (dk, sizeof(dk)); burn (dk, sizeof(dk));
burn (&keyInfo, sizeof (keyInfo)); burn (&keyInfo, sizeof (keyInfo));
#if !defined(_UEFI)
VirtualUnlock (&keyInfo, sizeof (keyInfo));
VirtualUnlock (&dk, sizeof (dk));
#endif // !defined(_UEFI)
*retInfo = cryptoInfo;
return 0; return 0;
} }