-
Notifications
You must be signed in to change notification settings - Fork 142
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Actual behavior
The docs for this say: "A pointer to a variable that receives a pointer to the security descriptor of the object. When you have finished using the pointer, free the returned buffer by calling the LocalFree function.".
Expected behavior
That the friendly overload for this (and any) function returning a value that requires freeing/releasing of resources be wrapped in the appropriate SafeHandle type, especially if CsWin32 already provides the SafeHandle type.
Repro steps
NativeMethods.txtcontent:
GetNamedSecurityInfo
-
NativeMethods.jsoncontent (if present): N/A -
Any of your own code that should be shared?
internal unsafe static WIN32_ERROR GetNamedSecurityInfo(string pObjectName, SE_OBJECT_TYPE ObjectType, OBJECT_SECURITY_INFORMATION SecurityInfo, out SafeNoReleaseHandle? ppsidOwner, out SafeNoReleaseHandle? ppsidGroup, out LocalFreeSafeHandle? ppDacl, out LocalFreeSafeHandle? ppSacl, out LocalFreeSafeHandle ppSecurityDescriptor)
{
fixed (char* pObjectNameLocal = pObjectName)
{
PSID psidOwner = default, pSidGroup = default; ACL* pDacl = null, pSacl = null; PSECURITY_DESCRIPTOR pSecurityDescriptor = default;
var res = PInvoke.GetNamedSecurityInfo(pObjectNameLocal, ObjectType, SecurityInfo, &psidOwner, &pSidGroup, &pDacl, &pSacl, &pSecurityDescriptor);
if (res != WIN32_ERROR.ERROR_SUCCESS)
{
throw ExceptionUtilities.GetExceptionForLastWin32Error(res);
}
if (pSecurityDescriptor == default)
{
throw new InvalidOperationException("Failed to retrieve security descriptor.");
}
ppsidOwner = psidOwner != default ? new((IntPtr)psidOwner.Value) : null;
ppsidGroup = pSidGroup != default ? new((IntPtr)pSidGroup.Value) : null;
ppDacl = pDacl is not null ? new((IntPtr)pDacl, false) : null;
ppSacl = pSacl is not null ? new((IntPtr)pSacl, false) : null;
ppSecurityDescriptor = new((IntPtr)pSecurityDescriptor, true);
return res;
}
}Context
- CsWin32 version: 0.3.253
- Win32Metadata version (if explicitly set by project): N/A
- Target Framework: net472
LangVersion(if explicitly set by project): N/A
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working