From fdd123ad9818d9af47f371ffe6dd7cc312c57f16 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 16 Jun 2021 13:31:03 +0300 Subject: [PATCH] [#607] network: Prevent potential panic in `Address.Equal` method Make `Address.Equal` method to accept value instead of pointer in order to prevent NPE. Signed-off-by: Leonard Lyubich --- cmd/neofs-node/config/node/config_test.go | 2 +- cmd/neofs-node/object.go | 2 +- pkg/network/address.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/neofs-node/config/node/config_test.go b/cmd/neofs-node/config/node/config_test.go index d5335bbde..9c89df7bd 100644 --- a/cmd/neofs-node/config/node/config_test.go +++ b/cmd/neofs-node/config/node/config_test.go @@ -50,7 +50,7 @@ func TestNodeSection(t *testing.T) { require.NoError(t, err) require.Equal(t, "NbUgTSFvPmsRxmGeWpuuGeJUoRoi6PErcM", key.Address()) - require.Equal(t, true, addr.Equal(expectedAddr)) + require.Equal(t, true, addr.Equal(*expectedAddr)) require.Equal(t, true, relay) require.Len(t, attributes, 2) diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index 65efb40db..0dbd4647c 100644 --- a/cmd/neofs-node/object.go +++ b/cmd/neofs-node/object.go @@ -503,7 +503,7 @@ func (c *reputationClientConstructor) Get(addr *network.Address) (client.Client, for i := range nm.Nodes { netAddr, err := network.AddressFromString(nm.Nodes[i].Address()) if err == nil { - if netAddr.Equal(addr) { + if netAddr.Equal(*addr) { prm := truststorage.UpdatePrm{} prm.SetPeer(reputation.PeerIDFromBytes(nm.Nodes[i].PublicKey())) diff --git a/pkg/network/address.go b/pkg/network/address.go index 214e1cd1a..d2905fd66 100644 --- a/pkg/network/address.go +++ b/pkg/network/address.go @@ -49,7 +49,7 @@ func (a Address) String() string { } // Equal compares Address's. -func (a Address) Equal(addr *Address) bool { +func (a Address) Equal(addr Address) bool { return a.ma.Equal(addr.ma) } @@ -129,7 +129,7 @@ func multiaddrStringFromHostAddr(host string) (string, error) { // IsLocalAddress returns true if network endpoint from local address // source is equal to network endpoint of passed address. func IsLocalAddress(src LocalAddressSource, addr *Address) bool { - return src.LocalAddress().Equal(addr) + return src.LocalAddress().Equal(*addr) } // HostAddrFromMultiaddr converts "/dns4/localhost/tcp/8080" to "localhost:8080".