[p2p] Malformed external address causes SIGSEGV (if URL has empty host) (#2564)
fix #2071 Signed-off-by: phymbert <pierrick.hymbert@gmail.com>
This commit is contained in:
parent
f471fc4963
commit
1d8348d707
|
@ -13,6 +13,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"errors"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -97,16 +98,19 @@ func NewNetAddressStringWithOptionalID(addr string) (*NetAddress, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ErrNetAddressInvalid{addrWithoutProtocol, err}
|
return nil, ErrNetAddressInvalid{addrWithoutProtocol, err}
|
||||||
}
|
}
|
||||||
|
if len(host) == 0 {
|
||||||
|
return nil, ErrNetAddressInvalid{
|
||||||
|
addrWithoutProtocol,
|
||||||
|
errors.New("host is empty")}
|
||||||
|
}
|
||||||
|
|
||||||
ip := net.ParseIP(host)
|
ip := net.ParseIP(host)
|
||||||
if ip == nil {
|
if ip == nil {
|
||||||
if len(host) > 0 {
|
ips, err := net.LookupIP(host)
|
||||||
ips, err := net.LookupIP(host)
|
if err != nil {
|
||||||
if err != nil {
|
return nil, ErrNetAddressLookup{host, err}
|
||||||
return nil, ErrNetAddressLookup{host, err}
|
|
||||||
}
|
|
||||||
ip = ips[0]
|
|
||||||
}
|
}
|
||||||
|
ip = ips[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
port, err := strconv.ParseUint(portStr, 10, 16)
|
port, err := strconv.ParseUint(portStr, 10, 16)
|
||||||
|
|
|
@ -49,6 +49,7 @@ func TestNewNetAddressStringWithOptionalID(t *testing.T) {
|
||||||
|
|
||||||
{"tcp://@127.0.0.1:8080", "", false},
|
{"tcp://@127.0.0.1:8080", "", false},
|
||||||
{"tcp://@", "", false},
|
{"tcp://@", "", false},
|
||||||
|
{"tcp://:26656", "", false},
|
||||||
{"", "", false},
|
{"", "", false},
|
||||||
{"@", "", false},
|
{"@", "", false},
|
||||||
{" @", "", false},
|
{" @", "", false},
|
||||||
|
|
Loading…
Reference in New Issue