fs: Filter out valid paths and volnames. (#1321)

This commit is contained in:
Harshavardhana 2016-04-16 19:33:29 -07:00
parent b2ec7da9f9
commit 33633fd15d
3 changed files with 3 additions and 3 deletions

View File

@ -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
}

View File

@ -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.

2
fs.go
View File

@ -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)