summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCedric Staniewski <cedric@gmx.ca>2016-07-03 11:19:12 +0000
committerJakob Borg <jakob@nym.se>2016-07-03 11:19:12 +0000
commita58f69be04b7cefe28fcaf6b4ba470ac1538d098 (patch)
treee9bc5aa22ac7a299719b9c86a910f10b168bec73
parente194eb1f6982ae0506c7b5149de3bc6529a67d97 (diff)
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
-rw-r--r--cmd/discosrv/querysrv.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/cmd/discosrv/querysrv.go b/cmd/discosrv/querysrv.go
index 6d55be79d..a0f730997 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()
}