Browse Source

Add sanity checking for modified svcMap while iterating through it.
Suggestion from @DerZade
Fixes https://github.com/moby/moby/pull/43444#discussion_r1033364679
Fixes #43442

Signed-off-by: Martin Ashby <martin@ashbysoft.com>

Martin Ashby 2 years ago
parent
commit
349c515ef8
1 changed files with 7 additions and 1 deletions
  1. 7 1
      libnetwork/network.go

+ 7 - 1
libnetwork/network.go

@@ -2001,7 +2001,13 @@ func (n *network) ResolveName(req string, ipType int) ([]net.IP, bool) {
 				strings.HasSuffix(req, strings.TrimPrefix(key, "*"))) {
 			selectedKey = key
 			ok = true
-			ipSet, _ = sr.svcMap.Get(selectedKey)
+			var found bool
+			ipSet, found = sr.svcMap.Get(selectedKey)
+			if !found {
+				logrus.Errorf("svcMap changed unexpectedly looking for key %s", key)
+				continue
+			}
+
 			break
 		}
 	}