From f33a730cd0c449cfd6f7106780c73052e96cc33d Mon Sep 17 00:00:00 2001 From: qmuntal Date: Fri, 27 Mar 2026 14:36:53 +0100 Subject: [PATCH] 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 LUCI-TryBot-Result: Go LUCI Reviewed-by: Damien Neil --- windows/security_windows.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/windows/security_windows.go b/windows/security_windows.go index a8b0364c..6c955cea 100644 --- a/windows/security_windows.go +++ b/windows/security_windows.go @@ -1438,13 +1438,17 @@ func GetSecurityInfo(handle Handle, objectType SE_OBJECT_TYPE, securityInformati } // GetNamedSecurityInfo queries the security information for a given named object and returns the self-relative security -// descriptor result on the Go heap. +// descriptor result on the Go heap. The security descriptor might be nil, even when err is nil, if the object exists +// but has no security descriptor. func GetNamedSecurityInfo(objectName string, objectType SE_OBJECT_TYPE, securityInformation SECURITY_INFORMATION) (sd *SECURITY_DESCRIPTOR, err error) { var winHeapSD *SECURITY_DESCRIPTOR err = getNamedSecurityInfo(objectName, objectType, securityInformation, nil, nil, nil, nil, &winHeapSD) if err != nil { return } + if winHeapSD == nil { + return nil, nil + } defer LocalFree(Handle(unsafe.Pointer(winHeapSD))) return winHeapSD.copySelfRelativeSecurityDescriptor(), nil }