From 33633fd15d0cabc930af8a8e3dc97d55e927d16b Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 16 Apr 2016 19:33:29 -0700 Subject: [PATCH] fs: Filter out valid paths and volnames. (#1321) --- fs-dir-common.go | 2 +- fs-utils.go | 2 +- fs.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fs-dir-common.go b/fs-dir-common.go index 6db10d0e8..207777a0c 100644 --- a/fs-dir-common.go +++ b/fs-dir-common.go @@ -134,7 +134,7 @@ func treeWalk(bucketDir, prefixDir, entryPrefixMatch, marker string, recursive b hasReserved := hasReservedPrefix(dirent.name) || hasReservedSuffix(dirent.name) // All dirents which match prefix and do not have reserved // keywords in them are valid entries. - return strings.HasPrefix(dirent.name, entryPrefixMatch) && !hasReserved + return strings.HasPrefix(dirent.name, entryPrefixMatch) && !hasReserved && isValidPath(dirent.name) } return false } diff --git a/fs-utils.go b/fs-utils.go index bf3da0a3b..c2e354ed6 100644 --- a/fs-utils.go +++ b/fs-utils.go @@ -60,7 +60,7 @@ func isValidPath(path string) bool { // isValidPrefix verifies where the prefix is a valid path. func isValidPrefix(prefix string) bool { // Prefix can be empty. - if prefix == "" { + if prefix == "" || prefix == "/" { return true } // Verify if prefix is a valid path. diff --git a/fs.go b/fs.go index e1af593f4..e11a60091 100644 --- a/fs.go +++ b/fs.go @@ -143,7 +143,7 @@ func removeDuplicateVols(vols []VolInfo) []VolInfo { func getAllUniqueVols(dirPath string) ([]VolInfo, error) { volumeFn := func(dirent fsDirent) bool { // Return all directories. - return dirent.IsDir() + return dirent.IsDir() && isValidVolname(dirent.name) } namesOnly := false // Returned dirent names are absolute. dirents, err := scandir(dirPath, volumeFn, namesOnly)