Windows Setup: Avoid potential issues by correctly initializing variables and checking memory allocation.

This commit is contained in:
Mounir IDRASSI 2015-03-19 13:06:19 +01:00
parent 474505d704
commit a5203dd006

View File

@ -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,7 +244,8 @@ 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 (pDacl)
{
if (TRUE == ::InitializeAcl(pDacl, dwAclSize, ACL_REVISION))
{
if (TRUE == AddAccessAllowedAceEx(pDacl, ACL_REVISION, CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE, WRITE_DAC | KEY_ALL_ACCESS, pSid))
@ -263,6 +262,7 @@ static void AllowKeyAccess(HKEY Key,const char* SubKeyName)
}
delete [] pDacl;
}
}
if (pTokenUser)
HeapFree(GetProcessHeap(), 0, pTokenUser);