aboutsummaryrefslogtreecommitdiff
path: root/libgo
diff options
context:
space:
mode:
authorNikhil Benesch <nikhil.benesch@gmail.com>2020-10-13 07:06:11 +0000
committerIan Lance Taylor <iant@golang.org>2020-10-13 22:19:35 -0700
commit7355c1df55e28f3298b14a621968f9a27fdcd2bf (patch)
tree33298f04c7891854d25177057e79703325866cc9 /libgo
parent78fbe731a8822e819c4ca0e6d6f777c7a2f36bad (diff)
downloadgcc-7355c1df55e28f3298b14a621968f9a27fdcd2bf.zip
gcc-7355c1df55e28f3298b14a621968f9a27fdcd2bf.tar.gz
gcc-7355c1df55e28f3298b14a621968f9a27fdcd2bf.tar.bz2
syscall: port fix for netbsd unix sockets from upstream
NetBSD does not include the null terminator when in its reported socket length. Port the upstream bugfix for the issue (#6627). This was likely missed during the usual upstream merge because the gc and gccgo socket implementations have diverged quite a bit. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/261741
Diffstat (limited to 'libgo')
-rw-r--r--libgo/go/syscall/socket_bsd.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/libgo/go/syscall/socket_bsd.go b/libgo/go/syscall/socket_bsd.go
index f62457f..40637bc 100644
--- a/libgo/go/syscall/socket_bsd.go
+++ b/libgo/go/syscall/socket_bsd.go
@@ -52,13 +52,19 @@ func (sa *RawSockaddrUnix) setLen(n int) {
}
func (sa *RawSockaddrUnix) getLen() (int, error) {
- if sa.Len < 3 || sa.Len > SizeofSockaddrUnix {
+ if sa.Len < 2 || sa.Len > SizeofSockaddrUnix {
return 0, EINVAL
}
- n := int(sa.Len) - 3 // subtract leading Family, Len, terminating NUL.
+
+ // Some BSDs include the trailing NUL in the length, whereas
+ // others do not. Work around this by subtracting the leading
+ // family and len. The path is then scanned to see if a NUL
+ // terminator still exists within the length.
+ n := int(sa.Len) - 2 // subtract leading Family, Len
for i := 0; i < n; i++ {
if sa.Path[i] == 0 {
- // found early NUL; assume Len is overestimating.
+ // found early NUL; assume Len included the NUL
+ // or was overestimating.
n = i
break
}