From d9cb7e273916d7d6335c73aeacba75ae642ac0e4 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 2 Jun 2020 10:19:51 +0100 Subject: [PATCH] lib/connections: Skip and warn on malformed URLs (fixes #6697) (#6699) --- lib/connections/service.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/connections/service.go b/lib/connections/service.go index 980c468d8..8096bacb0 100644 --- a/lib/connections/service.go +++ b/lib/connections/service.go @@ -601,14 +601,25 @@ func (s *service) CommitConfiguration(from, to config.Configuration) bool { continue } - if _, ok := s.listeners[addr]; ok { - seen[addr] = struct{}{} + uri, err := url.Parse(addr) + if err != nil { + l.Warnf("Skipping malformed listener URL %q: %v", addr, err) continue } - uri, err := url.Parse(addr) - if err != nil { - l.Infof("Parsing listener address %s: %v", addr, err) + // Make sure we always have the canonical representation of the URL. + // This is for consistency as we use it as a map key, but also to + // avoid misunderstandings. We do not just use the canonicalized + // version, because an URL that looks very similar to a human might + // mean something entirely different to the computer (e.g., + // tcp:/127.0.0.1:22000 in fact being equivalent to tcp://:22000). + if canonical := uri.String(); canonical != addr { + l.Warnf("Skipping malformed listener URL %q (not canonical)", addr) + continue + } + + if _, ok := s.listeners[addr]; ok { + seen[addr] = struct{}{} continue }