cmd/discosrv: Respect the listen address scheme (fixes #3346)

If the listen address scheme is set to tcp4:// or tcp6://, it needs to be
made sure that the remote address matches this scheme before it is added to
the database.

This prevents invalid URIs like tcp4://<IPv6 address>:<port> or tcp6://<IPv4
address>:<port>.

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3378
This commit is contained in:
Cedric Staniewski 2016-07-03 11:19:12 +00:00 committed by Jakob Borg
parent e194eb1f69
commit a58f69be04

View File

@ -330,6 +330,16 @@ func (s *querysrv) handleAnnounce(ctx context.Context, remote net.IP, deviceID p
ip := net.ParseIP(host) ip := net.ParseIP(host)
if host == "" || ip.IsUnspecified() { if host == "" || ip.IsUnspecified() {
// Do not use IPv6 remote address if requested scheme is tcp4
if uri.Scheme == "tcp4" && remote.To4() == nil {
continue
}
// Do not use IPv4 remote address if requested scheme is tcp6
if uri.Scheme == "tcp6" && remote.To4() != nil {
continue
}
host = remote.String() host = remote.String()
} }