Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: remove trailing null from unix abstract socket address #5678

Merged
merged 1 commit into from Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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