Fix: Avoid a false type assertion in the inmemory driver

This issue was discovered by the following fuzzer:
https://github.com/cncf/cncf-fuzzing/blob/main/projects/distribution/inmemory_fuzzer.go#L24

Signed-off-by: Milos Gajdos <milosthegajdos@gmail.com>
pull/3579/head
Milos Gajdos 2022-01-28 10:54:07 +00:00
parent be4c921514
commit 676691ce6d
No known key found for this signature in database
GPG Key ID: 01300E5E6D417439
1 changed files with 7 additions and 2 deletions

View File

@ -244,11 +244,16 @@ func (d *dir) delete(p string) error {
return errNotExists
}
if _, ok := parent.(*dir).children[filename]; !ok {
parentDir, ok := parent.(*dir)
if !ok {
return errIsNotDir
}
if _, ok := parentDir.children[filename]; !ok {
return errNotExists
}
delete(parent.(*dir).children, filename)
delete(parentDir.children, filename)
return nil
}