Skip to content

Commit 54521b2

Browse files
authored
client: remove trailing null from unix abstract socket address (#5678)
1 parent 36e4810 commit 54521b2

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

examples/features/unix_abstract/server/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (s *ecServer) UnaryEcho(ctx context.Context, req *pb.EchoRequest) (*pb.Echo
5151
func main() {
5252
flag.Parse()
5353
netw := "unix"
54-
socketAddr := fmt.Sprintf("\x00%v", *addr)
54+
socketAddr := fmt.Sprintf("@%v", *addr)
5555
lis, err := net.Listen(netw, socketAddr)
5656
if err != nil {
5757
log.Fatalf("net.Listen(%q, %q) failed: %v", netw, socketAddr, err)

internal/resolver/unix/unix.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ func (b *builder) Build(target resolver.Target, cc resolver.ClientConn, _ resolv
4949
}
5050
addr := resolver.Address{Addr: endpoint}
5151
if b.scheme == unixAbstractScheme {
52-
// prepend "\x00" to address for unix-abstract
53-
addr.Addr = "\x00" + addr.Addr
52+
// We can not prepend \0 as c++ gRPC does, as in Golang '@' is used to signify we do
53+
// not want trailing \0 in address.
54+
addr.Addr = "@" + addr.Addr
5455
}
5556
cc.UpdateState(resolver.State{Addresses: []resolver.Address{networktype.Set(addr, "unix")}})
5657
return &nopResolver{}, nil

test/authority_test.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ var authorityTests = []authorityTest{
125125
},
126126
{
127127
name: "UnixAbstract",
128-
address: "\x00abc efg",
128+
address: "@abc efg",
129129
target: "unix-abstract:abc efg",
130130
authority: "localhost",
131-
dialTargetWant: "\x00abc efg",
131+
dialTargetWant: "unix:@abc efg",
132132
},
133133
}
134134

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

0 commit comments

Comments
 (0)