浏览代码

Prevent deadlock on attempt to use own net

Signed-off-by: Aidan Hobson Sayers <aidanhs@cantab.net>
Aidan Hobson Sayers 10 年之前
父节点
当前提交
f30d1c1835
共有 2 个文件被更改,包括 11 次插入0 次删除
  1. 3 0
      daemon/container.go
  2. 8 0
      integration-cli/docker_cli_run_test.go

+ 3 - 0
daemon/container.go

@@ -1515,6 +1515,9 @@ func (container *Container) getNetworkedContainer() (*Container, error) {
 		if err != nil {
 			return nil, err
 		}
+		if container == nc {
+			return nil, fmt.Errorf("cannot join own network")
+		}
 		if !nc.IsRunning() {
 			return nil, fmt.Errorf("cannot join network of a non running container: %s", parts[1])
 		}

+ 8 - 0
integration-cli/docker_cli_run_test.go

@@ -2657,6 +2657,14 @@ func (s *DockerSuite) TestContainerNetworkMode(c *check.C) {
 	}
 }
 
+func (s *DockerSuite) TestContainerNetworkModeToSelf(c *check.C) {
+	cmd := exec.Command(dockerBinary, "run", "--name=me", "--net=container:me", "busybox", "true")
+	out, _, err := runCommandWithOutput(cmd)
+	if err == nil || !strings.Contains(out, "cannot join own network") {
+		c.Fatalf("using container net mode to self should result in an error")
+	}
+}
+
 func (s *DockerSuite) TestRunModePidHost(c *check.C) {
 	testRequires(c, NativeExecDriver, SameHostDaemon)