Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/shared/Communication.cpp

Issue 6308036998070272: Release DACL after the named pipe was created (Closed)
Patch Set: Created July 1, 2014, 4:51 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/shared/Communication.cpp
===================================================================
--- a/src/shared/Communication.cpp
+++ b/src/shared/Communication.cpp
@@ -100,13 +100,13 @@
explicitAccess[1].Trustee.ptstrName = static_cast<LPWSTR>(allAppContainersSid);
PACL acl = 0;
+ // acl has to be released after this
if (SetEntriesInAcl(2, explicitAccess, 0, &acl) != ERROR_SUCCESS)
return std::auto_ptr<SECURITY_DESCRIPTOR>(0);
- std::tr1::shared_ptr<ACL> sharedAcl(static_cast<ACL*>(acl), LocalFree); // Just to simplify cleanup
+ // This only references the acl, not copies it
if (!SetSecurityDescriptorDacl(securityDescriptor.get(), TRUE, acl, FALSE))
return std::auto_ptr<SECURITY_DESCRIPTOR>(0);
-
}
// Create a dummy security descriptor with low integrirty preset and copy its SACL into ours
@@ -131,6 +131,18 @@
}
}
+ // Releases the DACL structure in the provided security descriptor
+ void ReleaseDacl(PSECURITY_DESCRIPTOR securityDescriptor)
+ {
+ BOOL aclPresent = FALSE;
+ BOOL aclDefaulted = FALSE;
+ PACL acl;
+ GetSecurityDescriptorDacl(securityDescriptor, &aclPresent, &acl, &aclDefaulted);
+ if (aclPresent)
+ {
+ LocalFree(acl);
+ }
+ }
const std::wstring Communication::pipeName = L"\\\\.\\pipe\\adblockplusengine_" + GetUserName();
void Communication::InputBuffer::CheckType(Communication::ValueType expectedType)
@@ -182,7 +194,7 @@
securityAttributes.bInheritHandle = TRUE;
std::tr1::shared_ptr<SECURITY_DESCRIPTOR> sharedSecurityDescriptor; // Just to simplify cleanup
-
+
AutoHandle token;
OpenProcessToken(GetCurrentProcess(), TOKEN_READ, token);
@@ -191,12 +203,20 @@
std::auto_ptr<SID> logonSid = GetLogonSid(token);
// Create a SECURITY_DESCRIPTOR that has both Low Integrity and allows access to all AppContainers
// This is needed since IE likes to jump out of Enhanced Protected Mode for specific pages (bing.com)
+
+ // ATTENTION: DACL in the returned securityDescriptor has to be manually released by ReleaseDacl
std::auto_ptr<SECURITY_DESCRIPTOR> securityDescriptor = CreateSecurityDescriptor(logonSid.get());
+
securityAttributes.lpSecurityDescriptor = securityDescriptor.release();
sharedSecurityDescriptor.reset(static_cast<SECURITY_DESCRIPTOR*>(securityAttributes.lpSecurityDescriptor));
}
pipe = CreateNamedPipeW(pipeName.c_str(), PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES, bufferSize, bufferSize, 0, &securityAttributes);
+
+ if (IsWindowsVistaOrLater())
+ {
+ ReleaseDacl(securityAttributes.lpSecurityDescriptor);
+ }
}
else
{
@@ -215,12 +235,12 @@
DWORD pipeMode = PIPE_READMODE_MESSAGE | PIPE_WAIT;
if (!SetNamedPipeHandleState(pipe, &pipeMode, 0, 0))
- throw std::runtime_error("SetNamedPipeHandleState failed: error " + GetLastError());
+ throw std::runtime_error(AppendErrorCode("SetNamedPipeHandleState failed"));
if (mode == MODE_CREATE && !ConnectNamedPipe(pipe, 0))
{
DWORD err = GetLastError();
- throw std::runtime_error("Client failed to connect: error " + GetLastError());
+ throw std::runtime_error(AppendErrorCode("Client failed to connect"));
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld