Skip to content

Commit 73288ad

Browse files
committed
windows: refactor (*SD).copySelfRelativeSecurityDescriptor and (*SD).String
1 parent 73c410a commit 73288ad

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

windows/security_windows.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,19 +1226,12 @@ func (sd *SECURITY_DESCRIPTOR) IsValid() bool {
12261226
// used with %v formatting directives.
12271227
func (sd *SECURITY_DESCRIPTOR) String() string {
12281228
var sddl *uint16
1229-
var strLen uint32
1230-
err := convertSecurityDescriptorToStringSecurityDescriptor(sd, 1, 0xff, &sddl, &strLen)
1229+
err := convertSecurityDescriptorToStringSecurityDescriptor(sd, 1, 0xff, &sddl, nil)
12311230
if err != nil {
12321231
return ""
12331232
}
12341233
defer LocalFree(Handle(unsafe.Pointer(sddl)))
1235-
1236-
var utf16s []uint16
1237-
h := (*unsafeheader.Slice)(unsafe.Pointer(&utf16s))
1238-
h.Data = unsafe.Pointer(sddl)
1239-
h.Len = int(strLen)
1240-
h.Cap = int(strLen)
1241-
return UTF16ToString(utf16s)
1234+
return UTF16PtrToString(sddl)
12421235
}
12431236

12441237
// ToAbsolute converts a self-relative security descriptor into an absolute one.
@@ -1316,12 +1309,15 @@ func (absoluteSD *SECURITY_DESCRIPTOR) ToSelfRelative() (selfRelativeSD *SECURIT
13161309
}
13171310

13181311
func (selfRelativeSD *SECURITY_DESCRIPTOR) copySelfRelativeSecurityDescriptor() *SECURITY_DESCRIPTOR {
1319-
var dst, src []byte
1320-
dst = make([]byte, selfRelativeSD.Length())
1312+
sdLen := (int)(selfRelativeSD.Length())
1313+
1314+
var src []byte
13211315
h := (*unsafeheader.Slice)(unsafe.Pointer(&src))
13221316
h.Data = unsafe.Pointer(selfRelativeSD)
1323-
h.Len = len(dst)
1324-
h.Cap = len(dst)
1317+
h.Len = sdLen
1318+
h.Cap = sdLen
1319+
1320+
dst := make([]byte, sdLen)
13251321
copy(dst, src)
13261322
return (*SECURITY_DESCRIPTOR)(unsafe.Pointer(&dst[0]))
13271323
}

0 commit comments

Comments
 (0)