Skip to content

Commit f33a730

Browse files
committed
windows: support nil security descriptor on GetNamedSecurityInfo
GetNamedSecurityInfoW may return a nil security descriptor when the object exists but has no security descriptor. This change allows GetNamedSecurityInfo to return a nil *SECURITY_DESCRIPTOR in that case, instead of crashing when trying to copy the nil security descriptor. Fixes golang/go#78396 Change-Id: I2f8d26a431e0a5c3de535cf8983db1465acc24fe Reviewed-on: https://go-review.googlesource.com/c/sys/+/760160 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
1 parent 493d172 commit f33a730

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

windows/security_windows.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,13 +1438,17 @@ func GetSecurityInfo(handle Handle, objectType SE_OBJECT_TYPE, securityInformati
14381438
}
14391439

14401440
// GetNamedSecurityInfo queries the security information for a given named object and returns the self-relative security
1441-
// descriptor result on the Go heap.
1441+
// descriptor result on the Go heap. The security descriptor might be nil, even when err is nil, if the object exists
1442+
// but has no security descriptor.
14421443
func GetNamedSecurityInfo(objectName string, objectType SE_OBJECT_TYPE, securityInformation SECURITY_INFORMATION) (sd *SECURITY_DESCRIPTOR, err error) {
14431444
var winHeapSD *SECURITY_DESCRIPTOR
14441445
err = getNamedSecurityInfo(objectName, objectType, securityInformation, nil, nil, nil, nil, &winHeapSD)
14451446
if err != nil {
14461447
return
14471448
}
1449+
if winHeapSD == nil {
1450+
return nil, nil
1451+
}
14481452
defer LocalFree(Handle(unsafe.Pointer(winHeapSD)))
14491453
return winHeapSD.copySelfRelativeSecurityDescriptor(), nil
14501454
}

0 commit comments

Comments
 (0)