Browse code

Merge pull request #31384 from allencloud/validate-extrahosts-in-deamon-side

validate extraHosts in daemon side

Vincent Demeester authored on 2017/03/01 02:28:10
Showing 2 changed files
... ...
@@ -266,6 +266,12 @@ func (daemon *Daemon) verifyContainerSettings(hostConfig *containertypes.HostCon
266 266
 		return nil, fmt.Errorf("can't create 'AutoRemove' container with restart policy")
267 267
 	}
268 268
 
269
+	for _, extraHost := range hostConfig.ExtraHosts {
270
+		if _, err := opts.ValidateExtraHost(extraHost); err != nil {
271
+			return nil, err
272
+		}
273
+	}
274
+
269 275
 	for port := range hostConfig.PortBindings {
270 276
 		_, portStr := nat.SplitProtoPort(string(port))
271 277
 		if _, err := nat.ParsePort(portStr); err != nil {
... ...
@@ -16,6 +16,7 @@ import (
16 16
 	networktypes "github.com/docker/docker/api/types/network"
17 17
 	"github.com/docker/docker/container"
18 18
 	"github.com/docker/docker/daemon/network"
19
+	"github.com/docker/docker/opts"
19 20
 	"github.com/docker/docker/pkg/stringid"
20 21
 	"github.com/docker/docker/runconfig"
21 22
 	"github.com/docker/go-connections/nat"
... ...
@@ -117,6 +118,9 @@ func (daemon *Daemon) buildSandboxOptions(container *container.Container) ([]lib
117 117
 
118 118
 	for _, extraHost := range container.HostConfig.ExtraHosts {
119 119
 		// allow IPv6 addresses in extra hosts; only split on first ":"
120
+		if _, err := opts.ValidateExtraHost(extraHost); err != nil {
121
+			return nil, err
122
+		}
120 123
 		parts := strings.SplitN(extraHost, ":", 2)
121 124
 		sboxOptions = append(sboxOptions, libnetwork.OptionExtraHost(parts[0], parts[1]))
122 125
 	}