Skip to content

Commit

Permalink
[#607] network: Prevent potential panic in Address.Equal method
Browse files Browse the repository at this point in the history
Make `Address.Equal` method to accept value instead of pointer in order to
prevent NPE.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
  • Loading branch information
Leonard Lyubich authored and cthulhu-rider committed Jun 18, 2021
1 parent 6de0af0 commit fdd123a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/neofs-node/config/node/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/neofs-node/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))

Expand Down
4 changes: 2 additions & 2 deletions pkg/network/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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".
Expand Down

0 comments on commit fdd123a

Please sign in to comment.