Browse code

fix parsing of hostnames when we actually want IP addresses.

Docker-DCO-1.1-Signed-off-by: Erik Hollensbe <github@hollensbe.org> (github: erikh)

Erik Hollensbe authored on 2014/08/08 06:23:28
Showing 1 changed files
... ...
@@ -5,6 +5,7 @@ package nat
5 5
 
6 6
 import (
7 7
 	"fmt"
8
+	"net"
8 9
 	"strconv"
9 10
 	"strings"
10 11
 
... ...
@@ -114,6 +115,9 @@ func ParsePortSpecs(ports []string) (map[Port]struct{}, map[Port][]PortBinding,
114 114
 			hostPort      = parts["hostPort"]
115 115
 		)
116 116
 
117
+		if rawIp != "" && net.ParseIP(rawIp) == nil {
118
+			return nil, nil, fmt.Errorf("Invalid ip address: %s", rawIp)
119
+		}
117 120
 		if containerPort == "" {
118 121
 			return nil, nil, fmt.Errorf("No port specified: %s<empty>", rawPort)
119 122
 		}
... ...
@@ -123,6 +127,7 @@ func ParsePortSpecs(ports []string) (map[Port]struct{}, map[Port][]PortBinding,
123 123
 		if _, err := strconv.ParseUint(hostPort, 10, 16); hostPort != "" && err != nil {
124 124
 			return nil, nil, fmt.Errorf("Invalid hostPort: %s", hostPort)
125 125
 		}
126
+
126 127
 		if !validateProto(proto) {
127 128
 			return nil, nil, fmt.Errorf("Invalid proto: %s", proto)
128 129
 		}