Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local adapter clean user input before file access #1037

Merged
merged 10 commits into from
Dec 30, 2020
6 changes: 4 additions & 2 deletions block/local/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ func (l *Adapter) getPath(identifier block.ObjectPointer) (string, error) {
if err != nil {
return "", err
}
return path.Join(l.path, obj.StorageNamespace, obj.Key), nil
p := path.Join(l.path, obj.StorageNamespace, obj.Key)
return filepath.Clean(p), nil
}

// maybeMkdir runs f(path), but if f fails due to file-not-found MkdirAll's its dir and then
Expand All @@ -96,7 +97,8 @@ func maybeMkdir(path string, f func(p string) (*os.File, error)) (*os.File, erro
if !errors.Is(err, os.ErrNotExist) {
return ret, err
}
if err = os.MkdirAll(filepath.Dir(path), 0777); err != nil {
d := filepath.Dir(filepath.Clean(path))
if err = os.MkdirAll(d, 0777); err != nil {
return nil, err
}
return f(path)
Expand Down