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

master
Harshavardhana 8 years ago
parent b2ec7da9f9
commit 33633fd15d
  1. 2
      fs-dir-common.go
  2. 2
      fs-utils.go
  3. 2
      fs.go

@ -134,7 +134,7 @@ func treeWalk(bucketDir, prefixDir, entryPrefixMatch, marker string, recursive b
hasReserved := hasReservedPrefix(dirent.name) || hasReservedSuffix(dirent.name) hasReserved := hasReservedPrefix(dirent.name) || hasReservedSuffix(dirent.name)
// All dirents which match prefix and do not have reserved // All dirents which match prefix and do not have reserved
// keywords in them are valid entries. // 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 return false
} }

@ -60,7 +60,7 @@ func isValidPath(path string) bool {
// isValidPrefix verifies where the prefix is a valid path. // isValidPrefix verifies where the prefix is a valid path.
func isValidPrefix(prefix string) bool { func isValidPrefix(prefix string) bool {
// Prefix can be empty. // Prefix can be empty.
if prefix == "" { if prefix == "" || prefix == "/" {
return true return true
} }
// Verify if prefix is a valid path. // Verify if prefix is a valid path.

@ -143,7 +143,7 @@ func removeDuplicateVols(vols []VolInfo) []VolInfo {
func getAllUniqueVols(dirPath string) ([]VolInfo, error) { func getAllUniqueVols(dirPath string) ([]VolInfo, error) {
volumeFn := func(dirent fsDirent) bool { volumeFn := func(dirent fsDirent) bool {
// Return all directories. // Return all directories.
return dirent.IsDir() return dirent.IsDir() && isValidVolname(dirent.name)
} }
namesOnly := false // Returned dirent names are absolute. namesOnly := false // Returned dirent names are absolute.
dirents, err := scandir(dirPath, volumeFn, namesOnly) dirents, err := scandir(dirPath, volumeFn, namesOnly)

Loading…
Cancel
Save