From a58f69be04b7cefe28fcaf6b4ba470ac1538d098 Mon Sep 17 00:00:00 2001 From: Cedric Staniewski Date: Sun, 3 Jul 2016 11:19:12 +0000 Subject: [PATCH] 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://: or tcp6://:. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3378 --- cmd/discosrv/querysrv.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/discosrv/querysrv.go b/cmd/discosrv/querysrv.go index 6d55be79..a0f73099 100644 --- a/cmd/discosrv/querysrv.go +++ b/cmd/discosrv/querysrv.go @@ -330,6 +330,16 @@ func (s *querysrv) handleAnnounce(ctx context.Context, remote net.IP, deviceID p ip := net.ParseIP(host) 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() }