Merge pull request #3268 from vieux/prevent_panic_volume

prevent a panic with docker run -v /
This commit is contained in:
Guillaume J. Charmes 2013-12-18 14:06:44 -08:00
commit 681b40c801
3 changed files with 6 additions and 2 deletions

View File

@ -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 '/'")
}
}

View File

@ -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")

View File

@ -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 {