فهرست منبع

Merge pull request #3268 from vieux/prevent_panic_volume

prevent a panic with docker run -v /
Guillaume J. Charmes 11 سال پیش
والد
کامیت
681b40c801
3فایلهای تغییر یافته به همراه6 افزوده شده و 2 حذف شده
  1. 2 0
      commands.go
  2. 3 1
      commands_unit_test.go
  3. 1 1
      container.go

+ 2 - 0
commands.go

@@ -1814,6 +1814,8 @@ func parseRun(cmd *flag.FlagSet, args []string, capabilities *Capabilities) (*Co
 			flVolumes.Set(dstDir)
 			binds = append(binds, bind)
 			flVolumes.Delete(bind)
+		} else if bind == "/" {
+			return nil, nil, cmd, fmt.Errorf("Invalid volume: path can't be '/'")
 		}
 	}
 

+ 3 - 1
commands_unit_test.go

@@ -128,7 +128,9 @@ func TestParseRunVolumes(t *testing.T) {
 		t.Fatalf("Error parsing volume flags, without volume, no volume should be present. Received %v", config.Volumes)
 	}
 
-	mustParse(t, "-v /")
+	if _, _, err := parse(t, "-v /"); err == nil {
+		t.Fatalf("Expected error, but got none")
+	}
 
 	if _, _, err := parse(t, "-v /:/"); err == nil {
 		t.Fatalf("Error parsing volume flags, `-v /:/` should fail but didn't")

+ 1 - 1
container.go

@@ -836,7 +836,7 @@ func (container *Container) createVolumes() error {
 		volPath = path.Join(container.RootfsPath(), volPath)
 		rootVolPath, err := utils.FollowSymlinkInScope(volPath, container.RootfsPath())
 		if err != nil {
-			panic(err)
+			return err
 		}
 
 		if _, err := os.Stat(rootVolPath); err != nil {