Skip to content

Commit

Permalink
Avoid net.ResolveUDPAddr in snet.UDPAddrFromString (#3662)
Browse files Browse the repository at this point in the history
Parse the host IP, port directly instead of using net.ResolveUDPAddr, which also resolves hostnames. Hostnames should not be considered inside SCION addresses.

Fixes #3654
  • Loading branch information
matzf committed Feb 11, 2020
1 parent ea92fee commit b502b46
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions go/lib/snet/udpaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"net"
"regexp"
"strconv"
"strings"

"github.com/scionproto/scion/go/lib/addr"
Expand Down Expand Up @@ -65,14 +66,20 @@ func UDPAddrFromString(s string) (*UDPAddr, error) {
if ip := net.ParseIP(strings.Trim(rawHost, "[]")); ip != nil {
return &UDPAddr{IA: ia, Host: &net.UDPAddr{IP: ip, Port: 0}}, nil
}
udpAddr, err := net.ResolveUDPAddr("udp", rawHost)

rawIP, rawPort, err := net.SplitHostPort(rawHost)
if err != nil {
return nil, err
}
if udpAddr.IP == nil {
ip := net.ParseIP(rawIP)
if ip == nil {
return nil, serrors.New("invalid address: no IP specified", "host", rawHost)
}
return &UDPAddr{IA: ia, Host: udpAddr}, nil
port, err := strconv.ParseUint(rawPort, 10, 16)
if err != nil {
return nil, serrors.New("invalid port", "host", rawHost)
}
return &UDPAddr{IA: ia, Host: &net.UDPAddr{IP: ip, Port: int(port)}}, nil
}

// Network implements net.Addr interface.
Expand Down

0 comments on commit b502b46

Please sign in to comment.