From 3c49cb17fb6014519925a069ad81c30ff41b3d7f Mon Sep 17 00:00:00 2001 From: Erik Hollensbe Date: Thu, 7 Aug 2014 14:23:28 -0700 Subject: [PATCH] fix parsing of hostnames when we actually want IP addresses. Docker-DCO-1.1-Signed-off-by: Erik Hollensbe (github: erikh) --- nat/nat.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nat/nat.go b/nat/nat.go index ef89eaa0fe..643a2979c0 100644 --- a/nat/nat.go +++ b/nat/nat.go @@ -5,6 +5,7 @@ package nat import ( "fmt" + "net" "strconv" "strings" @@ -114,6 +115,9 @@ func ParsePortSpecs(ports []string) (map[Port]struct{}, map[Port][]PortBinding, hostPort = parts["hostPort"] ) + if rawIp != "" && net.ParseIP(rawIp) == nil { + return nil, nil, fmt.Errorf("Invalid ip address: %s", rawIp) + } if containerPort == "" { return nil, nil, fmt.Errorf("No port specified: %s", rawPort) } @@ -123,6 +127,7 @@ func ParsePortSpecs(ports []string) (map[Port]struct{}, map[Port][]PortBinding, if _, err := strconv.ParseUint(hostPort, 10, 16); hostPort != "" && err != nil { return nil, nil, fmt.Errorf("Invalid hostPort: %s", hostPort) } + if !validateProto(proto) { return nil, nil, fmt.Errorf("Invalid proto: %s", proto) }