Avoid crash on invalid Move arguments
This chnage prevents a crash when moving from a non-existent directory that has a file as a parent. To prevent this, we simply check that the node is a directory and throws an error if it is not. Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
@@ -212,12 +212,17 @@ func (d *dir) move(src, dst string) error {
|
||||
return errNotExists
|
||||
}
|
||||
|
||||
s, ok := sp.(*dir).children[srcFilename]
|
||||
spd, ok := sp.(*dir)
|
||||
if !ok {
|
||||
return errIsNotDir // paranoid.
|
||||
}
|
||||
|
||||
s, ok := spd.children[srcFilename]
|
||||
if !ok {
|
||||
return errNotExists
|
||||
}
|
||||
|
||||
delete(sp.(*dir).children, srcFilename)
|
||||
delete(spd.children, srcFilename)
|
||||
|
||||
switch n := s.(type) {
|
||||
case *dir:
|
||||
|
Reference in New Issue
Block a user