Skip to content

Commit dc3b788

Browse files
cuonglmmdempsky
authored andcommitted
syscall: fix wrong unsafe.Pointer alignment in syscall
Caught with: go test -a -short -gcflags=all=-d=checkptr log/syslog and: grep -rE '\*\[([^2]|.{2,})\].*\)\(unsafe.Pointer' syscall Updates #34972 Change-Id: Iafd199b3a34beb7cc3e88484bf2fbae45183f951 Reviewed-on: https://go-review.googlesource.com/c/go/+/201877 Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 65a4dc9 commit dc3b788

File tree

5 files changed

+7
-5
lines changed

5 files changed

+7
-5
lines changed

src/syscall/security_windows.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,15 @@ func LookupSID(system, account string) (sid *SID, domain string, accType uint32,
157157
// String converts sid to a string format
158158
// suitable for display, storage, or transmission.
159159
func (sid *SID) String() (string, error) {
160+
// From https://docs.microsoft.com/en-us/windows/win32/secbiomet/general-constants
161+
const SecurityMaxSidSize = 68
160162
var s *uint16
161163
e := ConvertSidToStringSid(sid, &s)
162164
if e != nil {
163165
return "", e
164166
}
165167
defer LocalFree((Handle)(unsafe.Pointer(s)))
166-
return UTF16ToString((*[256]uint16)(unsafe.Pointer(s))[:]), nil
168+
return UTF16ToString((*[SecurityMaxSidSize]uint16)(unsafe.Pointer(s))[:]), nil
167169
}
168170

169171
// Len returns the length, in bytes, of a valid security identifier sid.

src/syscall/syscall_bsd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func anyToSockaddr(rsa *RawSockaddrAny) (Sockaddr, error) {
242242
break
243243
}
244244
}
245-
bytes := (*[10000]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
245+
bytes := (*[len(pp.Path)]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
246246
sa.Name = string(bytes)
247247
return sa, nil
248248

src/syscall/syscall_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ func anyToSockaddr(rsa *RawSockaddrAny) (Sockaddr, error) {
484484
for n < len(pp.Path) && pp.Path[n] != 0 {
485485
n++
486486
}
487-
bytes := (*[10000]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
487+
bytes := (*[len(pp.Path)]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
488488
sa.Name = string(bytes)
489489
return sa, nil
490490

src/syscall/syscall_solaris.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func anyToSockaddr(rsa *RawSockaddrAny) (Sockaddr, error) {
293293
for n < len(pp.Path) && pp.Path[n] != 0 {
294294
n++
295295
}
296-
bytes := (*[10000]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
296+
bytes := (*[len(pp.Path)]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
297297
sa.Name = string(bytes)
298298
return sa, nil
299299

src/syscall/syscall_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ func (rsa *RawSockaddrAny) Sockaddr() (Sockaddr, error) {
765765
for n < len(pp.Path) && pp.Path[n] != 0 {
766766
n++
767767
}
768-
bytes := (*[10000]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
768+
bytes := (*[len(pp.Path)]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
769769
sa.Name = string(bytes)
770770
return sa, nil
771771

0 commit comments

Comments
 (0)