From 996d2e2a1000e8acd534f1826773cd49dca330a6 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 22 Mar 2016 17:03:11 -0700 Subject: [PATCH] bucketpolicy: checkBucketPolicy should keep resources in map. This is done to make sure to avoid appending duplicates for resources for each actions. --- bucket-policy-parser.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bucket-policy-parser.go b/bucket-policy-parser.go index 695cd97f7..0c8258eb4 100644 --- a/bucket-policy-parser.go +++ b/bucket-policy-parser.go @@ -193,7 +193,7 @@ var invalidPrefixActions = map[string]struct{}{ func checkBucketPolicy(bucket string, bucketPolicy BucketPolicy) APIErrorCode { // Validate statements for special actions and collect resources // for others to validate nesting. - var resources []string + var resourceMap = make(map[string]struct{}) for _, statement := range bucketPolicy.Statements { for _, action := range statement.Actions { for _, resource := range statement.Resources { @@ -211,12 +211,17 @@ func checkBucketPolicy(bucket string, bucketPolicy BucketPolicy) APIErrorCode { return ErrMalformedPolicy } // All valid resources collect them separately to verify nesting. - resources = append(resources, resourcePrefix) + resourceMap[resourcePrefix] = struct{}{} } } } } + var resources []string + for resource := range resourceMap { + resources = append(resources, resource) + } + // Sort strings as shorter first. sort.Strings(resources)