VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Setup
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2015-03-19 13:06:19 +0100
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2015-04-05 14:25:09 +0200
commita5203dd006a1b0cb96b8730309e84eb409fa93b2 (patch)
treeb8af2ac8e0b144db84201521f0c4e47dbb61fcc8 /src/Setup
parent474505d704e003a0acac0b41f59c7c2e820edaa7 (diff)
downloadVeraCrypt-a5203dd006a1b0cb96b8730309e84eb409fa93b2.tar.gz
VeraCrypt-a5203dd006a1b0cb96b8730309e84eb409fa93b2.zip
Windows Setup: Avoid potential issues by correctly initializing variables and checking memory allocation.
Diffstat (limited to 'src/Setup')
-rw-r--r--src/Setup/Setup.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/Setup/Setup.c b/src/Setup/Setup.c
index b24b479d..bc080714 100644
--- a/src/Setup/Setup.c
+++ b/src/Setup/Setup.c
@@ -202,17 +202,15 @@ static void RecursiveSetDACL (HKEY hKey, const char* SubKeyName, PSECURITY_DESCR
static void AllowKeyAccess(HKEY Key,const char* SubKeyName)
{
LSTATUS RegResult;
- HKEY SvcKey;
- DWORD dwLength;
+ HKEY SvcKey = NULL;
+ DWORD dwLength = 0;
HANDLE Token = NULL;
- PTOKEN_USER pTokenUser;
+ PTOKEN_USER pTokenUser = NULL;
std::string sNewSD;
RegResult = RegOpenKeyExA(Key, SubKeyName, 0, WRITE_OWNER | KEY_READ, &SvcKey);
if (RegResult==ERROR_SUCCESS)
{
- dwLength=0;
- pTokenUser = NULL;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &Token))
{
if (!GetTokenInformation(Token, TokenUser, pTokenUser, 0, &dwLength))
@@ -246,22 +244,24 @@ static void AllowKeyAccess(HKEY Key,const char* SubKeyName)
PSID pSid = pTokenUser->User.Sid;
DWORD dwAclSize = sizeof(ACL) + sizeof(ACCESS_ALLOWED_ACE) + ::GetLengthSid(pSid) - sizeof(DWORD);
PACL pDacl = (PACL) new BYTE[dwAclSize];
-
- if (TRUE == ::InitializeAcl(pDacl, dwAclSize, ACL_REVISION))
+ if (pDacl)
{
- if (TRUE == AddAccessAllowedAceEx(pDacl, ACL_REVISION, CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE, WRITE_DAC | KEY_ALL_ACCESS, pSid))
+ if (TRUE == ::InitializeAcl(pDacl, dwAclSize, ACL_REVISION))
{
- SECURITY_DESCRIPTOR SecDesc;
- if (TRUE == ::InitializeSecurityDescriptor(&SecDesc, SECURITY_DESCRIPTOR_REVISION))
+ if (TRUE == AddAccessAllowedAceEx(pDacl, ACL_REVISION, CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE, WRITE_DAC | KEY_ALL_ACCESS, pSid))
{
- if (TRUE == ::SetSecurityDescriptorDacl(&SecDesc, TRUE, pDacl, FALSE))
+ SECURITY_DESCRIPTOR SecDesc;
+ if (TRUE == ::InitializeSecurityDescriptor(&SecDesc, SECURITY_DESCRIPTOR_REVISION))
{
- RecursiveSetDACL (Key, SubKeyName, &SecDesc);
+ if (TRUE == ::SetSecurityDescriptorDacl(&SecDesc, TRUE, pDacl, FALSE))
+ {
+ RecursiveSetDACL (Key, SubKeyName, &SecDesc);
+ }
}
}
}
+ delete [] pDacl;
}
- delete [] pDacl;
}
if (pTokenUser)