Browse code

Prevent deadlock on attempt to use own net

Signed-off-by: Aidan Hobson Sayers <aidanhs@cantab.net>

Aidan Hobson Sayers authored on 2015/04/27 09:07:30
Showing 2 changed files
... ...
@@ -1515,6 +1515,9 @@ func (container *Container) getNetworkedContainer() (*Container, error) {
1515 1515
 		if err != nil {
1516 1516
 			return nil, err
1517 1517
 		}
1518
+		if container == nc {
1519
+			return nil, fmt.Errorf("cannot join own network")
1520
+		}
1518 1521
 		if !nc.IsRunning() {
1519 1522
 			return nil, fmt.Errorf("cannot join network of a non running container: %s", parts[1])
1520 1523
 		}
... ...
@@ -2657,6 +2657,14 @@ func (s *DockerSuite) TestContainerNetworkMode(c *check.C) {
2657 2657
 	}
2658 2658
 }
2659 2659
 
2660
+func (s *DockerSuite) TestContainerNetworkModeToSelf(c *check.C) {
2661
+	cmd := exec.Command(dockerBinary, "run", "--name=me", "--net=container:me", "busybox", "true")
2662
+	out, _, err := runCommandWithOutput(cmd)
2663
+	if err == nil || !strings.Contains(out, "cannot join own network") {
2664
+		c.Fatalf("using container net mode to self should result in an error")
2665
+	}
2666
+}
2667
+
2660 2668
 func (s *DockerSuite) TestRunModePidHost(c *check.C) {
2661 2669
 	testRequires(c, NativeExecDriver, SameHostDaemon)
2662 2670