Browse code

daemon/libnetwork: Fix panic in findHNSEp when IP networks are nil

Can happen for `docker run --network none ...`

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>

Paweł Gronowski authored on 2026/01/08 23:00:27
Showing 1 changed files
... ...
@@ -251,9 +251,14 @@ func deleteEpFromResolverImpl(
251 251
 }
252 252
 
253 253
 func findHNSEp(ip4, ip6 *net.IPNet, hnsEndpoints []hcsshim.HNSEndpoint) *hcsshim.HNSEndpoint {
254
+	if ip4 == nil && ip6 == nil {
255
+		return nil
256
+	}
254 257
 	for _, hnsEp := range hnsEndpoints {
255
-		if (hnsEp.IPAddress != nil && hnsEp.IPAddress.Equal(ip4.IP)) ||
256
-			(hnsEp.IPv6Address != nil && hnsEp.IPv6Address.Equal(ip6.IP)) {
258
+		if ip4 != nil && hnsEp.IPAddress != nil && hnsEp.IPAddress.Equal(ip4.IP) {
259
+			return &hnsEp
260
+		}
261
+		if ip6 != nil && hnsEp.IPv6Address != nil && hnsEp.IPv6Address.Equal(ip6.IP) {
257 262
 			return &hnsEp
258 263
 		}
259 264
 	}