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:
commit
681b40c801
3 changed files with 6 additions and 2 deletions
|
@ -1814,6 +1814,8 @@ func parseRun(cmd *flag.FlagSet, args []string, capabilities *Capabilities) (*Co
|
||||||
flVolumes.Set(dstDir)
|
flVolumes.Set(dstDir)
|
||||||
binds = append(binds, bind)
|
binds = append(binds, bind)
|
||||||
flVolumes.Delete(bind)
|
flVolumes.Delete(bind)
|
||||||
|
} else if bind == "/" {
|
||||||
|
return nil, nil, cmd, fmt.Errorf("Invalid volume: path can't be '/'")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
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 {
|
if _, _, err := parse(t, "-v /:/"); err == nil {
|
||||||
t.Fatalf("Error parsing volume flags, `-v /:/` should fail but didn't")
|
t.Fatalf("Error parsing volume flags, `-v /:/` should fail but didn't")
|
||||||
|
|
|
@ -836,7 +836,7 @@ func (container *Container) createVolumes() error {
|
||||||
volPath = path.Join(container.RootfsPath(), volPath)
|
volPath = path.Join(container.RootfsPath(), volPath)
|
||||||
rootVolPath, err := utils.FollowSymlinkInScope(volPath, container.RootfsPath())
|
rootVolPath, err := utils.FollowSymlinkInScope(volPath, container.RootfsPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(rootVolPath); err != nil {
|
if _, err := os.Stat(rootVolPath); err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue