Skip to content

Commit

Permalink
unix: stop counting trailing NUL for abstract addresses starting with…
Browse files Browse the repository at this point in the history
… NUL

Changes trailing-NUL-counting behavior for abstract addresses
starting with the NUL character to be the same as abstract
addresses starting with the @ character.

For golang/go#63579.

Change-Id: I2f26de4bcf614c4635ad188b1afa3d14ebd9a95f
Reviewed-on: https://go-review.googlesource.com/c/sys/+/535955
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
F Y authored and gopherbot committed Oct 23, 2023
1 parent 1bfbee0 commit 1e63810
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion unix/syscall_aix.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, _Socklen, error) {
if n > 0 {
sl += _Socklen(n) + 1
}
if sa.raw.Path[0] == '@' {
if sa.raw.Path[0] == '@' || (sa.raw.Path[0] == 0 && sl > 3) {
// Check sl > 3 so we don't change unnamed socket behavior.
sa.raw.Path[0] = 0
// Don't count trailing NUL for abstract address.
sl--
Expand Down
12 changes: 11 additions & 1 deletion unix/syscall_internal_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ func TestSockaddrUnix_sockaddr(t *testing.T) {
slen: 2, // family (uint16)
},
{
name: "abstract",
name: "abstract_starting_with_at",
sa: &SockaddrUnix{
Name: "@",
},
Expand All @@ -526,6 +526,16 @@ func TestSockaddrUnix_sockaddr(t *testing.T) {
},
slen: 3, // family (uint16) + NULL
},
{
name: "abstract_starting_with_null",
sa: &SockaddrUnix{
Name: "\x00",
},
raw: &RawSockaddrUnix{
Family: AF_UNIX,
},
slen: 3, // family (uint16) + NULL
},
{
name: "named",
sa: &SockaddrUnix{
Expand Down
3 changes: 2 additions & 1 deletion unix/syscall_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@ func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, _Socklen, error) {
if n > 0 {
sl += _Socklen(n) + 1
}
if sa.raw.Path[0] == '@' {
if sa.raw.Path[0] == '@' || (sa.raw.Path[0] == 0 && sl > 3) {
// Check sl > 3 so we don't change unnamed socket behavior.
sa.raw.Path[0] = 0
// Don't count trailing NUL for abstract address.
sl--
Expand Down
3 changes: 2 additions & 1 deletion unix/syscall_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, _Socklen, error) {
if n > 0 {
sl += _Socklen(n) + 1
}
if sa.raw.Path[0] == '@' {
if sa.raw.Path[0] == '@' || (sa.raw.Path[0] == 0 && sl > 3) {
// Check sl > 3 so we don't change unnamed socket behavior.
sa.raw.Path[0] = 0
// Don't count trailing NUL for abstract address.
sl--
Expand Down
3 changes: 2 additions & 1 deletion windows/syscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,8 @@ func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, int32, error) {
if n > 0 {
sl += int32(n) + 1
}
if sa.raw.Path[0] == '@' {
if sa.raw.Path[0] == '@' || (sa.raw.Path[0] == 0 && sl > 3) {
// Check sl > 3 so we don't change unnamed socket behavior.
sa.raw.Path[0] = 0
// Don't count trailing NUL for abstract address.
sl--
Expand Down

0 comments on commit 1e63810

Please sign in to comment.