This libgo patch by Nikhil Benesch backports a fix for *BSD unix sockets from the master sources. *BSD does not include the null terminator when in its reported socketlength. Port the upstream bugfix for the issue (https://golang.org/issue/6627). This was likely missed during the usual upstream merge because the gc and gccgo socket implementations have diverged quite a bit. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline.
Ian
1f15bcd13f4019744deec3140b575101fbd651ba diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 8f71939862b..80e702fc3f5 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -fef8afc1876f4a1d5e9a8fd54c21bf5917966e10 +5e76d81ec120e05a59e6c7d173ddf8a3de466bd0 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/libgo/go/syscall/socket_bsd.go b/libgo/go/syscall/socket_bsd.go index f62457f2bdb..40637bc7818 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 }