1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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 {