Procházet zdrojové kódy

Merge pull request #272 from docker/fix_port_convert_panic

Trying to fix defensively a panic @nebuk89 encountered on ACI,
Guillaume Tardif před 5 roky
rodič
revize
e904ac86ad
2 změnil soubory, kde provedl 21 přidání a 1 odebrání
  1. 1 1
      azure/convert/ports.go
  2. 20 0
      azure/convert/ports_test.go

+ 1 - 1
azure/convert/ports.go

@@ -37,7 +37,7 @@ func ToPorts(ipAddr *containerinstance.IPAddress, ports []containerinstance.Cont
 			protocol = string(port.Protocol)
 		}
 		ip := ""
-		if ipAddr != nil {
+		if ipAddr != nil && ipAddr.IP != nil {
 			ip = *ipAddr.IP
 		}
 

+ 20 - 0
azure/convert/ports_test.go

@@ -72,6 +72,26 @@ func TestPortConvert(t *testing.T) {
 				},
 			},
 		},
+		{
+			name: "with nil ip value",
+			ip: &containerinstance.IPAddress{
+				IP: nil,
+			},
+			ports: []containerinstance.ContainerPort{
+				{
+					Protocol: "tcp",
+					Port:     to.Int32Ptr(80),
+				},
+			},
+			expected: []containers.Port{
+				{
+					HostPort:      80,
+					ContainerPort: 80,
+					HostIP:        "",
+					Protocol:      "tcp",
+				},
+			},
+		},
 		{
 			name: "skip nil ports",
 			ip:   nil,