Skip to content

Commit

Permalink
client: remove trailing null from unix abstract socket address (#5678)
Browse files Browse the repository at this point in the history
  • Loading branch information
jachor committed Sep 30, 2022
1 parent 36e4810 commit 54521b2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/features/unix_abstract/server/main.go
Expand Up @@ -51,7 +51,7 @@ func (s *ecServer) UnaryEcho(ctx context.Context, req *pb.EchoRequest) (*pb.Echo
func main() {
flag.Parse()
netw := "unix"
socketAddr := fmt.Sprintf("\x00%v", *addr)
socketAddr := fmt.Sprintf("@%v", *addr)
lis, err := net.Listen(netw, socketAddr)
if err != nil {
log.Fatalf("net.Listen(%q, %q) failed: %v", netw, socketAddr, err)
Expand Down
5 changes: 3 additions & 2 deletions internal/resolver/unix/unix.go
Expand Up @@ -49,8 +49,9 @@ func (b *builder) Build(target resolver.Target, cc resolver.ClientConn, _ resolv
}
addr := resolver.Address{Addr: endpoint}
if b.scheme == unixAbstractScheme {
// prepend "\x00" to address for unix-abstract
addr.Addr = "\x00" + addr.Addr
// We can not prepend \0 as c++ gRPC does, as in Golang '@' is used to signify we do
// not want trailing \0 in address.
addr.Addr = "@" + addr.Addr
}
cc.UpdateState(resolver.State{Addresses: []resolver.Address{networktype.Set(addr, "unix")}})
return &nopResolver{}, nil
Expand Down
8 changes: 3 additions & 5 deletions test/authority_test.go
Expand Up @@ -125,10 +125,10 @@ var authorityTests = []authorityTest{
},
{
name: "UnixAbstract",
address: "\x00abc efg",
address: "@abc efg",
target: "unix-abstract:abc efg",
authority: "localhost",
dialTargetWant: "\x00abc efg",
dialTargetWant: "unix:@abc efg",
},
}

Expand All @@ -155,9 +155,7 @@ func (s) TestUnixCustomDialer(t *testing.T) {
if address != test.dialTargetWant {
return nil, fmt.Errorf("expected target %v in custom dialer, instead got %v", test.dialTargetWant, address)
}
if !strings.HasPrefix(test.target, "unix-abstract:") {
address = address[len("unix:"):]
}
address = address[len("unix:"):]
return (&net.Dialer{}).DialContext(ctx, "unix", address)
}
runUnixTest(t, test.address, test.target, test.authority, dialer)
Expand Down

0 comments on commit 54521b2

Please sign in to comment.